AJAX Async FileUpload problem

Last post 11-07-2009 12:26 PM by anas. 1 replies.

Sort Posts:

  • AJAX Async FileUpload problem

    11-07-2009, 12:05 PM
    • Member
      20 point Member
    • rat170
    • Member since 04-17-2009, 8:11 PM
    • Posts 63

    Hi everyone,

    I am trying to upload files using AJAX Async FileUpload, it is working file on my local directory, but when I upload the page then it gives an error.

    Her is my aspx code

    <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <br />
        <cc1:AsyncFileUpload ID="AsyncFileUpload1" runat="server" 
            UploaderStyle="Modern" />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Upload" />


    And here is my vb code

        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            If (AsyncFileUpload1.HasFile) Then
                AsyncFileUpload1.SaveAs("/images/test/new.jpg")
            End If
        End Sub


    but it is giving following error

    System.IO.DirectoryNotFoundException: Could not find a part of the path 'c:\images\new.jpg'.

    Also I want to read the name of file being uploaded and then append it with the uploading directory.

    Thank You very much.

  • Re: AJAX Async FileUpload problem

    11-07-2009, 12:26 PM
    Answer
    • All-Star
      60,642 point All-Star
    • anas
    • Member since 09-21-2006, 4:31 AM
    • Palestinian Territory, Occupied
    • Posts 6,847
    • Moderator

    rat170:
            AsyncFileUpload1.SaveAs("/images/test/new.jpg")  

    Use server.MapPath to convert a relative path to physical one:

    AsyncFileUpload1.SaveAs(Server.MapPath("~/images/test/new.jpg"))

    rat170:
    Also I want to read the name of file being uploaded and then append it with the uploading directory.

    That will not work in all browsers.

    For example, firefox  doesn't send the full path of the uploaded file , it just send the file name.



    Regards,

    Anas Ghanem | Blog

Page 1 of 1 (2 items)