Click here to Skip to main content
15,885,745 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've created a class named "MyLongRunningClass" that contain a method bellow:
C#
public string ProcessLongRunningAction(IEnumerable<HttpPostedFileBase> files ,string id)
        {
            int currentIndex = 0;
            foreach (HttpPostedFileBase file in files)
            {
                currentIndex++;
                lock(syncRoot)
                {                
                 string path=HttpContext.Current.Server.MapPath("~//Content//images       //"+file.FileName);//Excecption is created here........
                  file.SaveAs(path);
                }
              Thread.Sleep(300);
            }
            return id;
        }

From the controller this method is called with list of file to save in images directory. whenever HttpContext.Current.Server.MapPath("~//Content//images//"+file.FileName) is executed NullReferenceException thrown, and HttpContext.Current is always null. Same thing happen when I use session. I don't know whats wrong with me. I need help Immediately. please tell me what should i do, sample code is more appreciable.
THANKS.......IN ADVANCE
Posted
Comments
suzand 11-Mar-14 9:00am    
please help me....I'm waiting for your valuable suggestion.

1 solution

First make sure, you have image file in the specified path..
And try something like this,

C#
Server.MapPath(@"~/Content/images/"+file.FileName);
 
Share this answer
 
Comments
suzand 13-Mar-14 5:19am    
HttpContext.Current always null how Server.MapPath(@"~/Content/images/"+file.FileName); will work.............???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900