File upload Save as problem

Discussion in 'ASP.NET 2.0' started by jgs3, Jun 11, 2007.

  1. What happens if you drop the ~ from the path?


    Jim
     
  2. Thanks for the reply Jim





    I took out the ~and a different error occurs and i'm not sure why it now wants to find C:\ which is obvously wrong. How to I get the fileupload.saveas to a specified folder on DASP. I noticed that I have to upload folder higher than my secure folder so mywebsite/upload/ as opposed to mywebsite/secure/addphoto.aspx. Does that matter???





    Do I need to reference the http:// or even the htdoc?





    Help i'm stuck with this one.








    thanks steve



    Could not find a part of the path 'c:\upload\Lanapsoft_468x60_Banner_ASPNET_01_031507.gif'.


    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.IO.DirectoryNotFoundException: Could not find a part of the path 'c:\upload\Lanapsoft_468x60_Banner_ASPNET_01_031507.gif'.

    Source Error:





    Code:
    Line 16:         if FileUpload1.FileName <> "" then 
    Line 17:         
    Line 18:             FileUpload1.SaveAs("/upload/" + FileUpload1.FileName)
    Line 19:             
    Line 20:             Dim p As New Photo(ddcollections.SelectedValue, txtName.Text, FileUpload1.FileName, txtDesc.Text)
    Source File: E:\web\mywebsite\htdocs\secure\addphoto.aspx Line: 18

    Stack Trace:





    Code:
    [DirectoryNotFoundException: Could not find a part of the path 'c:\upload\picture.gif'.]
       System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +2012864
       System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +998
       System.IO.FileStream..ctor(String path, FileMode mode) +65
       System.Web.HttpPostedFile.SaveAs(String filename) +87
       System.Web.UI.WebControls.FileUpload.SaveAs(String filename) +22
       ASP.secure_addphoto_aspx.Upload(Object sender, EventArgs e) in E:\web\mywebsite\htdocs\secure\addphoto.aspx:18
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
    
     
  3. Try this:


    FileUpload1.SaveAs(Server.MapPath("~/upload/")&amp; FileUpload1.FileName)


    Aristotle

    DiscountASP.NET
    www.DiscountASP.NET
     
  4. Hi

    I have developed an application that uploads images to a folder on DASP server. Application works fine when running on my local computer but when try and upload to /upload/ folder I get and error.


    The SaveAs method is configured to require a rooted path, and the path '~/upload/picture.jpg' is not rooted. 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.Web.HttpException: The SaveAs method is configured to require a rooted path, and the path '~/upload/picture.jpg' is not rooted.

    Source Error:





    Code:
    Line 16:         if FileUpload1.FileName <> "" then 
    Line 17:         
    Line 18:             FileUpload1.SaveAs("~/upload/" + FileUpload1.FileName)
    Line 19:             
    Line 20:             Dim p As New Photo(ddcollections.SelectedValue, txtName.Text, FileUpload1.FileName, txtDesc.Text)
    Source File: E:\web\mywebsite\htdocs\secure\addphoto.aspx Line: 18

    Stack Trace:





    Code:
    [HttpException (0x80004005): The SaveAs method is configured to require a rooted path, and the path '~/upload/ali on la coupa.jpg' is not rooted.]
       System.Web.HttpPostedFile.SaveAs(String filename) +3234095
       System.Web.UI.WebControls.FileUpload.SaveAs(String filename) +22
       ASP.secure_addphoto_aspx.Upload(Object sender, EventArgs e) in E:\web\mywwebsite\htdocs\secure\addphoto.aspx:18
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
    




    The upload folder is just under my site root so I assumed ~/upload/..... would find it but apparently not.





    Please can you direct me to either a reosurce with instructions on how to root this file Saveas.. method


    or


    Help me with the code .


    Many thanks





    Steve
     
  5. I've had the same problem..




    FileUpload1.SaveAs(Server.MapPath("~/upload/")+ FileUpload1.FileName);


    this works great.. i think youwrote '&amp;' the place of '+' accidently..
     

Share This Page