When I try to apply SaveAs to FileUpload I receive Exception Access to file denied

  • Thread starter Sergey Topychkanov
  • Start date
S

Sergey Topychkanov

When I try to apply SaveAs to FileUpload I receive Exception Access to file
denied when debugging on my local computer code for ASP.NET 3.5. I have
Windows Vista SP1 and Visual Studio 2008 Professional. Code is next

protected void BtnUpload_Click(object sender, EventArgs e)

{

string fileType = "image/pjpeg";

if (PictureFileUpload.PostedFile.ContentLength != 0) {

if (PictureFileUpload.PostedFile.ContentType == fileType)

{





LblContentType.Text =
PictureFileUpload.PostedFile.ContentType;

string destDir = Server.MapPath("");

string fileName = GetFileName();

string destPath = Path.Combine(destDir, fileName);

try

{

PictureFileUpload.SaveAs(destDir);

}

catch (Exception err){

LblContentType.Text = err.Message;

}

}

}

What to do? Please write me directly to (e-mail address removed)
 
E

Eliyahu Goldin

Direct answering technical questions contradicts online forum purpose and
culture.

Make sure asp.net working process has access rights to the directory.
 
G

Guest

When I try to apply SaveAs to FileUpload I receive Exception Access to file
denied when debugging on my local computer code for ASP.NET 3.5. I have
Windows Vista SP1 and Visual Studio 2008 Professional. Code is next

     protected void BtnUpload_Click(object sender, EventArgs e)

    {

        string fileType = "image/pjpeg";

        if (PictureFileUpload.PostedFile.ContentLength != 0) {

            if (PictureFileUpload.PostedFile.ContentType == fileType)

            {

                LblContentType.Text =
PictureFileUpload.PostedFile.ContentType;

                string destDir = Server.MapPath("");

                string fileName = GetFileName();

                string destPath = Path.Combine(destDir, fileName);

                try

                {

                    PictureFileUpload.SaveAs(destDir);

                }

                catch (Exception err){

                    LblContentType.Text = err.Message;

                }

       }

}

What to do? Please write me directly to (e-mail address removed)

Give write access to "Network Service" user and it should work.
Hope this helps.
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top