upload & save file in 'wwwroot'

Last post 10-29-2007 7:36 AM by naturehermit. 4 replies.

Sort Posts:

  • upload & save file in 'wwwroot'

    10-25-2007, 12:32 PM
    • Member
      2 point Member
    • thesti
    • Member since 10-06-2007, 3:08 AM
    • Posts 12
    Hi,

    i've just tested this at one computer
    i've published a site using the 'build' > 'publish web site' menu to the localhost
    it runs. but, when a function of my site to upload a file and save it, and error occured saying
    Access to the path 'Course/course8' is denied. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.UnauthorizedAccessException: Access to the path 'Course/course8' is denied. ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.


    i thought that ASPNET account doesn't have write privilege in wwwroot. but, what actually happening is the it's trying to create the 'course'+ID directory under the 'WINDOWS/system32' folder. i knew it because it works find in ASP .NET development server, and i trace until i found that it was there.

    i don't know if it work like this at other computers. but, how could i create a new directory under wwwroot's subfolder (in a matter of permission) and save an uploaded file there?

    thx
  • Re: upload & save file in 'wwwroot'

    10-25-2007, 12:57 PM
    • Participant
      1,362 point Participant
    • matrixIII
    • Member since 07-23-2007, 4:32 PM
    • Posts 400

    what is it trying to create a directory under 'WINDOWS/system32' folder if you are telling it to create a folder under wwwroot?

    If that is intentional then try giving 'ASPNET' user write access to 'WINDOWS/system32', although I would not recommend it.

    Remember to select "Mark as Answer" on the post that helped you find the solution!
  • Re: upload & save file in 'wwwroot'

    10-27-2007, 4:57 AM
    • Member
      2 point Member
    • thesti
    • Member since 10-06-2007, 3:08 AM
    • Posts 12
    this is the code that created the directory

    Directory.CreateDirectory("Course/"+dirName);

    i assume, that the current directory when i create the dir is 'Windows/system32'
    how to set the current directory to root folder of localhost ?

    thx
  • Re: upload & save file in 'wwwroot'

    10-29-2007, 7:24 AM
    Answer
    • Member
      562 point Member
    • sandeepthekka
    • Member since 10-23-2007, 6:53 AM
    • kerala
    • Posts 164
    string fileName = System.IO.Path.GetFileName(fluUpload.PostedFile.FileName);

    string ext = System.IO.Path.GetExtension(fluUpload.PostedFile.FileName);

    comment = new Comment();

    comment.CID = CID;

    comment.TID = TID;

    comment.UserName = Session[
    "UserName"].ToString();

    comment.Description = txtDescription.Text;

    comment.CommentDate =
    DateTime.Now;

    comment.FileName = System.IO.Path.GetFileName(fluUpload.PostedFile.FileName) == "" ? "" : System.IO.Path.GetFileName(fluUpload.PostedFile.FileName);

    if(fluUpload.FileName!="")

    fluUpload.PostedFile.SaveAs(Server.MapPath("TopicFile//") + fileName );

  • Re: upload & save file in 'wwwroot'

    10-29-2007, 7:36 AM
    Answer

    thesti:
    this is the code that created the directory

    Directory.CreateDirectory("Course/"+dirName);

    i assume, that the current directory when i create the dir is 'Windows/system32'
    how to set the current directory to root folder of localhost ?

    thx

     

    Firstly use path say..

    string uploadfolderpath = "~/wwwroot"

    and then use

    filePath = HttpContext.Current.Server.MapPath(uploadFolderPath); and then go about doing your stuff...

    Please Mark Post that helped you as answer, also include a summary of what solved the problem as it helps others in similar situations
Page 1 of 1 (5 items)
Microsoft Communities