Click here to Skip to main content
15,913,115 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

Im using webform with masterpage...in that i have taken fileupload and upload button..
when i browse image and upload...image is not saving in the folder...
IS this post back problem or code pblm???
or can i do this without using fileupload???

Thank you

C#
protected void RadBtn_Upload_Click(object sender, EventArgs e)
     {
         try
         {

   string filename=System.IO.Path.GetFileName(FileUpload.PostedFile.FileName);
            FileUpload.SaveAs(Server.MapPath("img/" + filename));


         }
         catch (Exception ex)
         {

             throw ex;

         }
Posted
Comments
aarif moh shaikh 15-May-15 1:43am    
What error you got ??
Member 11148509 15-May-15 1:45am    
Object reference not set to an instance of an object...when i keep break point and see i couldnot see filename stored in string...

1 solution

I think... after browse your file postback event called in your page that why your fileupload control lost it file name ...

So you have to check that..
and always check Hasfile condition before uploading file on server..

For Example :
C#
if (FileUpload.HasFile)
      { 
           string filename=System.IO.Path.GetFileName(FileUpload.PostedFile.FileName);
            FileUpload.SaveAs(Server.MapPath("img/" + filename)); 
      }



Thanks
AARIF SHAIKH
 
Share this answer
 
Comments
Member 11148509 15-May-15 2:17am    
ya i have tried this too ..when i execute that its not going inside the loop...i'm unable to understand what to do ..
aarif moh shaikh 15-May-15 3:24am    
this means file is not available in your fileupload control
Member 11148509 15-May-15 3:35am    
ya thats my problem im uplaoding file but its not avaialble in that ...might be postback problem

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