This is a migrated thread and some comments may be shown as answers.

Uploading files with radAsycUpload

2 Answers 113 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 14 Aug 2013, 05:57 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Hristo Valyavicharski
Telerik team
answered on 15 Aug 2013, 12:48 PM
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.
0
Kevin
Top achievements
Rank 1
answered on 15 Aug 2013, 01:09 PM
Hi,

thanks it works now
Tags
Upload (Obsolete)
Asked by
Kevin
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Kevin
Top achievements
Rank 1
Share this question
or