Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I have given file upload path and it not saving the uploaded file in the directory

What I have tried:

C#
String targetFolder =  Server.MapPath("~D:\\New folder");
file.SaveAs(Path.Combine(targetFolder, "file.txt"));
Posted
Updated 15-Mar-17 20:52pm
Comments
Prateek Dalbehera 16-Mar-17 2:38am    
please let us know what error/exception you are getting while uploading. It will help to narrow down. Check if the same file is already existing in the given path.

This link "https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.saveas(v=vs.110).aspx" may help.
Member 12605293 16-Mar-17 2:47am    
Hi Prateek
The file is uploaded but not saving in my local.Error Message "Is not a virtual path"

Server.MapPath Method[^]

There is this Caution on the above page:

Quote:
For security reasons, the AspEnableParentPaths property has a default value set to FALSE. Scripts will not have access to the physical directory structure unless AspEnableParentPaths is set to TRUE.


Without the specific error information, it is hard to say what is happening. At a guess, I would say that you're trying to access a path outside the scope of the app's security settings.
 
Share this answer
 
string folderPath = Server.MapPath("~/Files/");
       
    //Check whether Directory (Folder) exists.
    if (!Directory.Exists(folderPath))
    {
        //If Directory (Folder) does not exists. Create it.
        Directory.CreateDirectory(folderPath);
    }
 
    //Save the File to the Directory (Folder).
    FileUpload1.SaveAs(folderPath + Path.GetFileName(FileUpload1.FileName));
 
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