By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,049 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

Access to the path xxx is denied when saving HttpPostedFile file

P: n/a
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.
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <te******@centrum.sk> wrote in message
news:ux**************@tk2msftngp13.phx.gbl...
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.

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.