3

i want to save file upload file in 'C:\inetpub\wwwroot\Content\SpeechFile\' in visual studio i can save this files

if (file != null)
            {
                string urlfile;
                string path = Server.MapPath("~" + "\\Content\\Apk\\");
                string filename = System.IO.Path.GetFileName(file.FileName);
                while (System.IO.File.Exists(path + "\\" + filename))
                    filename = "1" + filename;
                urlfile = "../../Content/Apk/" + filename;
                file.SaveAs(path + filename);
                model.Fileurl = urlfile;
            }

but on server i have an error

Access to the path 'C:\inetpub\wwwroot\Content\SpeechFile\nokia 700.jpg' is denied.

Mohammad hossein
  • 255
  • 3
  • 8
  • 17
  • 2
    If you newly created the folder "SpeechFile" then please check the access rights on it. – watraplion May 17 '13 at 08:29
  • 1
    possible duplicate of [ASP.net Getting the error "Access to the path is denied." while trying to upload files to my Windows Server 2008 R2 Web server](http://stackoverflow.com/questions/19724297/asp-net-getting-the-error-access-to-the-path-is-denied-while-trying-to-upload) – T.Todua Jul 23 '14 at 15:50

2 Answers2

3

Generally the user account the application pool runs under will not have permissions to write to any sub-folders for security reasons. You will have to check which user your application runs under and then give that user write permissions to the SpeechFile folder. Make sure that is the only folder that you do give it write permissions to so that the security risk is minimised.

caveman_dick
  • 6,302
  • 3
  • 34
  • 49
1

The only way to solve this problem is to not write to that folder. You are not allowed to write to that folder .Just Tried to Give Access Rights to your Folder SpeechFile.

You may also use Environment.SpecialFolder to help you find where you need to go.

Rahul
  • 5,603
  • 6
  • 34
  • 57