Access to the path xxx is denied when saving HttpPostedFile file

  • Thread starter Thread starter terrorix
  • Start date Start date
T

terrorix

I want to save uploaded file to disk. I have this construction:

HttpPostedFile myFile = ((HttpRequest)Request).Files["myFile"];
if (myFile != null)
{
string fn = "c:\\Inetpub\\wwwroot\\MyWeb\\upload\\File_1";
try
{
myFile.SaveAs(fn);
lblMsg.Text = "File was uploaded and saved successfully!";
}
catch (Exception exp)
{
lblMsg.Text = "Saving uploaded file error! ... " + exp.Message;
}
}


And i allways get exception :
Access to the path xxx is denied when saving HttpPostedFile file.

What i'm going wrong? In IIS configuration of MyWeb on folder "upload" i set ut write permission.
 
Hi,

You need to set modify permissions for the folder in the Windows Explorer,
not the IIS management console. You will have to set it either for the
ASPNET account or for the NETWORK_SERVICE account - depending on your OS and
the context of the code. Also, I'd prefer to declare the
System.Web.UI.HtmlControls.HtmlInputFile control in the page class and then
call SaveAs on the PostedFile property:

HtmlInputFile1.PostedFile.SaveAs(path);

but once again - it's just my preference.

Hope this helps
Martin
terrorix said:
I want to save uploaded file to disk. I have this construction:

HttpPostedFile myFile = ((HttpRequest)Request).Files["myFile"];
if (myFile != null)
{
string fn = "c:\\Inetpub\\wwwroot\\MyWeb\\upload\\File_1";
try
{
myFile.SaveAs(fn);
lblMsg.Text = "File was uploaded and saved successfully!";
}
catch (Exception exp)
{
lblMsg.Text = "Saving uploaded file error! ... " + exp.Message;
}
}


And i allways get exception :
Access to the path xxx is denied when saving HttpPostedFile file.

What i'm going wrong? In IIS configuration of MyWeb on folder "upload" i
set ut write permission.
 
Back
Top