Click here to Skip to main content
16,020,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is my code_behind code
string imgname = UpImage.PostedFile.FileName;
string path = "~/images/"+ imgname;
UpImage.SaveAs(MapPath(path))
here UpImage is my fileuploadcontrol id and images is my folder name.but i'm unable to save my images into the folder.please help me.
Posted

I guess it's a permission issue. You need to provide write permission to the Upload ('images' in your case) folder.

Is it giving any error? Give more details so that exact issue can be identified.

You may also check this msdn link[^] about Uploading Files in ASP.NET. It also tells how to assign permissions to the upload folder.
 
Share this answer
 
v2
Comments
Hiren solanki 16-Sep-10 8:41am    
it has nothing to do with permission. See my Modified answer for clarity
Abhijit Jana 16-Sep-10 20:28pm    
@Hiren, I am not sure, If the problem is resolved or not, but this issue mainly comes when you host your web application on IIS. By default, application runs on ASP.NET Integrated engine which has full write access to your drives so you don't have any issue with the permission. But, when you upload the application on Server, problem may comes due to perission issue. Becaue 1 ) The folder where you are uploading file does not have write access 2 ) This is most important : Application Pool Identity. By default IIS Application pool having Network service identity, which does not have any write access to server, for that reason you need to give "Local System" identity for that application pool. Some times, you can resolve this using impersonation.
Just use

C#
string imgname = UpImage.FileName;


Instead of

C#
string imgname = UpImage.PostedFile.FileName;


and Give a Try.

[Edited for clarification of my answer]
UpImage.FileName returns just file name e.g. xyz.gif
and UpImage.PostedFile.FileName returns full path e.g. d:\abc\xyz.gif
so the concationation (string path = "~/images/"+ imgname) will be unknown location, thats why he is facing error.
 
Share this answer
 
v3
Comments
Ankur\m/ 16-Sep-10 8:25am    
Why what's the problem with "UpImage.PostedFile.FileName;" ?
virang 16-Sep-10 9:57am    
UpImage.PostedFile.FileName will return full path of image (e.g d:/myimage/test.jpg) while UpImage.FileName will return only file name(e.g(test.jpg)
Ankur\m/ 16-Sep-10 11:59am    
Thank you for the clarification and modifying the comment.

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