Access to the path xxx is denied when saving HttpPostedFile file

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.
 
M

Martin Dechev

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top