File Upload Path Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jphaycock@googlemail.com

    File Upload Path Problem

    Hi

    I have a webform in a sub folder called admin. The form has a file
    upload control on it. I'm trying to upload an image file to the root
    images folder of the app like this:

    filePath = "~/images/" + myUploadControl .FileName;
    myUploadControl .SaveAs(filePat h);

    I get an error about a rooted path:

    There was a problem uploading the file: System.Web.Http Exception: The
    SaveAs method is configured to require a rooted path and the path bla
    bla bla is not rooted.

    Can anyone tell me how to do this. I've wasted an entire morning on it
    and have a tight deadline looming

    Thanks

    John
  • Mark Rae [MVP]

    #2
    Re: File Upload Path Problem

    <jphaycock@goog lemail.comwrote in message
    news:e2e61250-5285-499c-b23d-7b235d3fe0f7@34 g2000hsh.google groups.com...
    I have a webform in a sub folder called admin. The form has a file
    upload control on it. I'm trying to upload an image file to the root
    images folder of the app like this:
    filePath = "~/images/" + myUploadControl .FileName;
    What happens if you try:

    filePath = Server.MapPath( "~/images/" + myUploadControl .FileName);


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • jphaycock@googlemail.com

      #3
      Re: File Upload Path Problem

      What happens if you try:
      >
      filePath = Server.MapPath( "~/images/" + myUploadControl .FileName);
      >
      --
      Mark Rae
      ASP.NET MVPhttp://www.markrae.net
      Hi Mark Thank you for your help

      That actually works Mark but I have a fresh problem now.

      When the app first starts it displays an image in a literal. The url
      for the image is stored in a database field in this format :


      I then use code like this to get the literal to display the image:

      string pageBanner = rs[1].ToString().Tri m();
      litIMG.Text = "<img src='" + pageBanner + "' alt='Page Banner' />";

      When I upload the new image with the file upload it is getting stored
      in the database like this:

      C:\Inetpub\wwwr oot\myapp\image s\myimage.jpg

      When I try to load this image into the literal like described above
      the image does not render. I looked in the source code and it's
      getting built properly (<img src='C:\Inetpub \wwwroot\myapp\ images
      \myimage.jpg'bu t it isn't rendering.

      Is there a way to map this absolute path back into a web path before I
      send it to the literal?

      Sorry for the long winded reply :)

      John

      Comment

      • Mark Rae [MVP]

        #4
        Re: File Upload Path Problem

        <jphaycock@goog lemail.comwrote in message
        news:10d69a07-202e-428a-b662-641e69a04d86@m7 3g2000hsh.googl egroups.com...
        Is there a way to map this absolute path back into a web path before I
        send it to the literal?
        Not as far as I know:


        Since you're already storing the absolute path in the database, why not
        store the relative path too...?


        --
        Mark Rae
        ASP.NET MVP


        Comment

        • jphaycock@googlemail.com

          #5
          Re: File Upload Path Problem

          On Aug 12, 2:24 pm, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
          <jphayc...@goog lemail.comwrote in message
          >
          news:10d69a07-202e-428a-b662-641e69a04d86@m7 3g2000hsh.googl egroups.com...
          >
          Is there a way to map this absolute path back into a web path before I
          send it to the literal?
          >
          Not as far as I know:http://www.google.co.uk/search?sourc...hl=en-GB&ie=UT...
          >
          Since you're already storing the absolute path in the database, why not
          store the relative path too...?
          >
          --
          Mark Rae
          ASP.NET MVPhttp://www.markrae.net
          Cheers Mark

          I don't know why I didn't think of this sooner but I'm just saving the
          filename to the database now and hard coding the path. I can do this
          since the path will always be the same.

          The main thing is that the fileUpload is working thanks to you.

          All the best

          John

          Comment

          Working...