Click here to Skip to main content
15,881,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to upload a file using file upload control but it is showing error: Path error. I am using this piece of code:
C#
string fn;
                if ((FileUploadfacImage.PostedFile != null) && (FileUploadfacImage.PostedFile.ContentLength > 0))
                {
                    fn = System.IO.Path.GetFileName(FileUploadfacImage.PostedFile.FileName);
                    string savelocation = Server.MapPath("Attachment/FacultyImages") + "/" + fn;
                    FileUploadfacImage.PostedFile.SaveAs(savelocation);
                    lblmsg.Visible = true;
                    lblmsg.ForeColor = System.Drawing.Color.Black;
                    lblmsg.Text = "Image Uploaded Successfully !!!";
                }
                else
                {
                    lblmsg.Visible = true;
                    lblmsg.ForeColor = System.Drawing.Color.Red;
                    lblmsg.Text = "Image not Uploaded  !!!";
                }


Now the problem is that when i am running my application on local host its working well and good but after publishing and uploading my website on server file upload doesn't work. Why it is so...
Posted
Comments
Varun Sareen 16-Feb-12 13:00pm    
If some error is coming then show us the error content. We might be able to help you better

Dear Friend,

It may be due to the permission settings on the particular folder in which you want to upload the file. Read Write permission is to be set up. Follow the links, might be helpful to you:-

File Upload with ASP.NET[^]

http://msdn.microsoft.com/en-us/library/aa479405.aspx[^]

Don't forget to mark this as your answer if it helps you out.

Thanks
 
Share this answer
 
Comments
Qureshali 15-Feb-12 4:26am    
Sir, I have referred the above links but it is giving me same result as file not uploaded. Please suggest me some other way to over come this problem.
Varun Sareen 16-Feb-12 12:59pm    
Dear Friend, In order to upload the files on the server sometimes extra privileges has to be given to the folder. Please refer to this link it might be helpful to you http://technet.microsoft.com/en-us/library/bb727008.aspx
Check once whether you are getting that saved folder(FacultyImages) in your published files.

I think that folder is not exist in your published files.
 
Share this answer
 
Comments
Qureshali 14-Feb-12 23:15pm    
Sir,
The folder exists after in my published files. Please help me out sir.
There are two places the permissions need to fixed at for upload to work:
1. IIS on the folder you want to upload you need to check the allow write check box
2. right click the actual folder in file explorer and allow everyone to write to this folder. Please remember the web user is a low permission user IIS_ somthing.
 
Share this answer
 

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