Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,
I try to upload and save file using JQuery file upload
and it works fine in localhost but doesn't work on server
can't save image in the folder

it's my code for save file
C#
var file = Request.Files[0];
Random rnd = new Random();
name = rnd.Next(111, 9999).ToString() + "_" + System.IO.Path.GetFileName(file.FileName);
string fullPath = Path.Combine(Server.MapPath("~/Content/Bannerimages"), name);
file.SaveAs(fullPath);


any help here ?

What I have tried:

I try the code above in the problem describtion
Posted
Comments
Dave Kreskowiak 5-Feb-16 19:54pm    
And the error would be?? You'll find that in the Application event log on the server.
Chances are good that you're using the default account to run your app on the server and it doesn't have write permissions to any folder on the server.
Heba Kamel 5-Feb-16 19:56pm    
the error is don't save image in folder ,
but I can read from folders normally how can I know I have permissions or not?
Dave Kreskowiak 5-Feb-16 20:02pm    
That's the not the error message. Everybody is going to want the EXACT error message from the event log. Otherwise we're just guessing at what the problem is.
Heba Kamel 6-Feb-16 5:11am    
The SaveAs method is configured to require a rooted path, and the path " " is not rooted
Dave Kreskowiak 6-Feb-16 13:02pm    
The path that's sent to SaveAs must start with a drive letter (C:\) or UNC (\\server\share\) identifier. The path you're getting back apparently does do that. You'll have to examine the content of fullPath, either in the debugger or by output it to a log file somewhere to see what you're getting.

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