File Upload Page difficulties.

Discussion in 'ASP.NET / ASP.NET Core' started by superwizbang, Oct 6, 2005.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Customer support has pawned me off to here. They refuse to answer a simple question concerning file upload. Basically, I have an upload page that I cannot get to work correctly. It is located at:
    http://www.qualityaquaticsonline.com/Commerce/Admin.aspx

    I have set all permissions for the parent folder as 777. The anonymous ASP user account has 150meg of space to which it can write to. I verified that the target folder inherited the parent permissions. The code is below. It was found onthese forums. When run, no file is uploaded although a server trip is made. Basically, I would like to write to the folder "htdocs\commerce\productimages". The code-behind user control resides in the "htdocs\commerce\" folder.

    They told me to use their COM object for uploads. When I asked them a similar question, they said I was using .NET framework for my coding and to use the inherent libraries there. Now they are telling me to use the COM object again. All I want to do is make a simple doggone upload page, iterate through selected items and upload them to a particular directory.Why is this so difficult? Flame all you want, we all need to learn. I am not a system admin. I do not run my own server. I simply taught myself ASP.NET and VB andsuffered through the errors. If you flame this post, please offer a solution too. Oh, and another reason I was using email and not this board was I didn't want to tell the world about vulnerabilities in my site. I guess I will just have them back it up if it gets hacked now. Thank you for your help in advance.

    -Ken

    _________________________

    'Grab the file name from its fully qualified path at client
    Dim strFileName As String = File1.PostedFile.FileName
    ' upload path and file
    Dim UploadFile As String = Server.MapPath("") & "\" & "ProductImages" & _
    System.IO.Path.GetFileName(strFileName)

    ''***** NEED CODE TO CHECK WHETHER FILE EXISTS AND PROMPT FOR OVERWRITE
    Try
    File1.PostedFile.SaveAs(UploadFile)
    ResultMsg.Text = "Upload Successful!"
    Catch ex As Exception
    ResultMsg.Text = "The file could not be uploaded"
    End Try

    _____________________

    <P>Select the Files to Upload to the Server:
    <INPUT id="File1" type="file" name="File1" runat="server"></P>
    <P><INPUT id="File2" type="file" name="File2" runat="server"></P>
    <P><asp:button id="Submit1" onclick="UploadMultipleFiles_Clicked" runat="server" Text="Upload Files"
    causesvalidation=False /></P>
    <ASP:LABEL id="ResultMsg" runat="server" ForeColor="#ff0033" Visible="False" />
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    do you get any error??

    Also the path doesn't look right to me

    Dim UploadFile As String = Server.MapPath('') & '\' & 'ProductImages' & _

    and you said you want to upload to /commerce/productimages. it should look like

    Server.MapPath('') & '\commerce\productimages'

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. Ok, getting closer. Now it appears that the code is looking locally for the file. I will have to do some more homework. Thank you. Here is the error as it resides now.


    System.IO.DirectoryNotFoundException: Could not find a part of the path "E:\web\qualityaqua\htdocs\commerce\commerce\productimages\dj.gif". at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at System.Web.HttpPostedFile.SaveAs(String filename) at ASPNET.StarterKit.Commerce.__Upload.UploadMultipleFiles_Clicked(Object sender, EventArgs e) in E:\Visual Studio Projects\VSWebCache\qualityaqua.web122.discountasp.net\commerce\_Upload.ascx.vb:line 40
     
  4. Bruce

    Bruce DiscountASP.NET Staff

    this si the problem

    E:\web\qualityaqua\htdocs\commerce\commerce\productimages\dj.gif

    seems like the path is wrong

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  5. That is correct. I got a reply from the support group and they directed me to where I could find the full path to my directory. This was all that I needed. It seems mappath maps to the folder of the application and not the "root" folder like it was stated on various sources. Notice the doubled "commerce" call? There should only be one subfolder named commerce in the string. Updating my string to only include the subfolder "productimages" did the trick.


    Thanks for your help and replies!


    -Ken
     
  6. Bruce

    Bruce DiscountASP.NET Staff

    ah.. i see.

    server.mappath ('\') gets your path to the application root rather than the site root i believe, that's why you have the wrong path.

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page