Uploading files with radAsycUpload

Thread is closed for posting
3 posts, 1 answers
  1. Kevin
    Kevin avatar
    265 posts
    Member since:
    Jun 2011

    Posted 14 Aug 2013 Link to this post

    I am trying to upload files to a folder and have been foloowing the examples online, but always get the following error.  It uploads a funky fiel name to the tempfolder then trys to find the file and upload, what is strange is that if more than 1 file it finds all but the last one and then erros out.  Dont get this one.

    telerik:RadAsyncUpload ID="RadUpload" runat="server" Width="260px" AllowedFileExtensions="pdf, docx, doc, xfdl" MultipleFileSelection="Automatic"
    TargetFolder="~/Uploads" TemporaryFolder="~/Uptemp"></telerik:RadAsyncUpload>
     
     
     
     'Upload all the files to a permanent location
                For Each file As UploadedFile In attachments.UploadedFiles
                    Dim TargetFolder As String = attachments.TargetFolder
                    file.SaveAs(TargetFolder & "Name " & file.GetName.ToString)
     
                    sql = "Insert PriorServiceUpload (intPriorServiceId, strUrl) VALUES (" & PriorId & ", '" & file.FileName & "')"
     
                    insertUpdateDelete(sql)
                Next


    Could not find file 'C:\inetpub\wwwroot\Recruiting\Uptemp\fpgummmw.syg'.
    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.FileNotFoundException: Could not find file 'C:\inetpub\wwwroot\Recruiting\Uptemp\fpgummmw.syg'.
     
    Source Error:
     
    Line 54:             For Each file As UploadedFile In attachments.UploadedFiles
    Line 55:                 Dim TargetFolder As String = attachments.TargetFolder
    Line 56:                 file.SaveAs(TargetFolder & "Name " & file.GetName.ToString)
  2. Answer
    Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 15 Aug 2013 Link to this post

    Hi Kevin,

    RadAsyncUpload moves the uploaded files to a TargetFolder after a postback. And at the moment you set Target path via the TargetFolder property. Then on button click postback is raised and RadAsyncUpload will automatically move uploaded files from Temporary to Target folders. This will happens before the button's on click event is fired. Later when it is fired files will be no longer accessible, because they were moved. To resolve the issue move your logic in RadAsyncUpload's OnFileUploaded event or remove the TargetFolder property. Then your code will be changed as follows:
    <telerik:RadAsyncUpload
        ID="attachments"
        runat="server"
        Width="260px"
        AllowedFileExtensions="pdf, docx, doc, xfdl"
        MultipleFileSelection="Automatic"
        TemporaryFolder="~/Uptemp">
    </telerik:RadAsyncUpload>
    <telerik:RadButton ID="rbUpload" runat="server" OnClick="rbUpload_Click" Text="Upload"></telerik:RadButton>

    Protected Sub rbUpload_Click(sender As Object, e As EventArgs)
        'Upload all the files to a permanent location
        For Each file As UploadedFile In attachments.UploadedFiles
            Dim TargetFolder As String = Server.MapPath("~/Uploads/")
            file.SaveAs(TargetFolder & "Name " & file.GetName.ToString)
     
            sql = "Insert PriorServiceUpload (intPriorServiceId, strUrl) VALUES (" & PriorId & ", '" & file.FileName & "')"
            insertUpdateDelete(sql)
        Next
    End Sub

    Also be sure that your application has write permissions to both Temp and Target folders.

    Regards,
    Hristo Valyavicharski
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kevin
    Kevin avatar
    265 posts
    Member since:
    Jun 2011

    Posted 15 Aug 2013 Link to this post

    Hi,

    thanks it works now
Back to Top