0

my aspx code.

<asp:FileUpload runat="server"  ID="file_PurchesItems"  />

my c# code.

string Fpurchesitems = string.Empty;
HttpPostedFile fileup = HttpContext.Current.Request.Files["file_PurchesItems"];
Fpurchesitems = "flinvoice_" + DateTime.Now.Date.ToString("dd_MM_yyyy") + "_" + fileup.FileName.ToString();
fileup.SaveAs(HttpContext.Current.Server.MapPath("Images1/")+ Fpurchesitems);

but I am getting httppostedfile is null.

What is wrong and how do I solve that?

rene
  • 41,474
  • 78
  • 114
  • 152
Rajesh
  • 19
  • 5
  • 3
    Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – rene Dec 30 '17 at 10:01
  • C# code is inside your webmethod – santosh singh Dec 30 '17 at 10:03
  • Don't you have a instance variable called `file_PurchesItems` where you can simply call `SaveAs` on? If you haven't then fix that. It prevents that you have to deal with the Request and its Files collection as you would need to take the naming container into account as well. Your error stems from the fact that `HttpContext.Current.Request.Files` doesn't contain an item called `file_PurchesItems` and you can easily use the debugger to inspect what it does contain. But again, you won't need that if your controls and code behind are in good shape. – rene Dec 30 '17 at 10:07
  • when i call fileupload in webmethod at that time.my fileupload selected file is not get in webmethod.please help me... – Rajesh Dec 30 '17 at 19:06

0 Answers0