469,623 Members | 1,800 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

Access to the path xxx is denied when saving HttpPostedFile file

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
1 4310
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.

Similar topics

12 posts views Thread by Ron Weldy | last post: by
3 posts views Thread by Shailesh Humbad | last post: by
1 post views Thread by Duffman | last post: by
3 posts views Thread by David Thielen | last post: by
9 posts views Thread by Wayne Smith | last post: by
1 post views Thread by Santosh | last post: by
5 posts views Thread by rn5a | last post: by
1 post views Thread by Ralph Watermann | last post: by
8 posts views Thread by Jeremy Ames | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.