Hi,
I have a short form that the end user fills it. When he hits the 'submit button' it saves the fields into a database table and it returns it's identity seed.
Now I added the RadAsyncUpload control, and need to associate the seed of the form with the uploaded file.
The problem is that the RadAsyncUpload.FileUploaded event runs before the 'submit button' event.
What is the workaround for this case?
Protected Sub RadAsyncUpload1_FileUploaded(sender As Object, e As Telerik.Web.UI.FileUploadedEventArgs) Handles RadAsyncUpload1.FileUploaded
Dim targetFolder As String = RadAsyncUpload1.TargetFolder
Dim newName As String = hdnPesquisaID.Value & System.Guid.NewGuid.ToString
e.File.SaveAs(Path.Combine(Server.MapPath(targetFolder), newName + e.File.GetExtension()))
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
hdnPesquisaID.Value = "returns identity seed from database"
End Sub
I have a short form that the end user fills it. When he hits the 'submit button' it saves the fields into a database table and it returns it's identity seed.
Now I added the RadAsyncUpload control, and need to associate the seed of the form with the uploaded file.
The problem is that the RadAsyncUpload.FileUploaded event runs before the 'submit button' event.
What is the workaround for this case?
Protected Sub RadAsyncUpload1_FileUploaded(sender As Object, e As Telerik.Web.UI.FileUploadedEventArgs) Handles RadAsyncUpload1.FileUploaded
Dim targetFolder As String = RadAsyncUpload1.TargetFolder
Dim newName As String = hdnPesquisaID.Value & System.Guid.NewGuid.ToString
e.File.SaveAs(Path.Combine(Server.MapPath(targetFolder), newName + e.File.GetExtension()))
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
hdnPesquisaID.Value = "returns identity seed from database"
End Sub
5 Answers, 1 is accepted
0
Hello Jorge,
I can suggest you to move the identity seed code from Button1_Click event to RadAsyncUpload1_FileUploaded in the following manner:
or remove Target Folder from the markup definition of RadAsyncUpload and save uploaded file in Button1_Click event instead of RadAsyncUpload1_FileUploaded:
All the best,
Hristo Valyavicharski
the Telerik team
I can suggest you to move the identity seed code from Button1_Click event to RadAsyncUpload1_FileUploaded in the following manner:
Protected
Sub
RadAsyncUpload1_FileUploaded(sender
As
Object
, e
As
Telerik.Web.UI.FileUploadedEventArgs)
Handles
RadAsyncUpload1.FileUploaded
hdnPesquisaID.Value =
"returns identity seed from database"
Dim
targetFolder
As
String
= RadAsyncUpload1.TargetFolder
Dim
newName
As
String
= hdnPesquisaID.Value & System.Guid.NewGuid.ToString
e.File.SaveAs(Path.Combine(Server.MapPath(targetFolder), newName + e.File.GetExtension()))
End
Sub
Protected
Sub
Button1_Click(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
Button1.Click
End
Sub
or remove Target Folder from the markup definition of RadAsyncUpload and save uploaded file in Button1_Click event instead of RadAsyncUpload1_FileUploaded:
Protected
Sub
Button1_Click(sender
As
Object
, e
As
EventArgs)
Handles
Button1.Click
hdnPesquisaID =
"returns identity seed from database"
Dim
targetFolder
As
String
=
"~/Uploads"
Dim
newName
As
String
= hdnPesquisaID & System.Guid.NewGuid.ToString
If
RadAsyncUpload1.UploadedFiles.Count
Then
RadAsyncUpload1.UploadedFiles(0).SaveAs((Path.Combine(Server.MapPath(targetFolder), newName)))
End
If
End
Sub
Protected
Sub
RadAsyncUpload1_FileUploaded(sender
As
Object
, e
As
FileUploadedEventArgs)
Handles
RadAsyncUpload1.FileUploaded
End
Sub
All the best,
Hristo Valyavicharski
the Telerik team
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 their blog feed now.
0

Jorge
Top achievements
Rank 1
answered on 01 Apr 2013, 08:50 PM
I tried to follow the suggested approach, but I'm getting the following 2 problems:
1) A exception is raised (System.IO.FileNotFoundException)::
E:\Projetos2013\PesquisasPropostasV2\App_Data\RadUploadTemp\1364848845283cursos.gif'
The file is not there anymore at the time of the button click is raised. This exception occurs when it tries to 'SaveAs'
2) The file is copied to it's expected destination but without being renamed as I needed.
1) A exception is raised (System.IO.FileNotFoundException)::
E:\Projetos2013\PesquisasPropostasV2\App_Data\RadUploadTemp\1364848845283cursos.gif'
The file is not there anymore at the time of the button click is raised. This exception occurs when it tries to 'SaveAs'
2) The file is copied to it's expected destination but without being renamed as I needed.
Protected
Sub
btnSalvar_Click(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
btnSalvar.Click
Dim
intPesquisaID
As
Integer
= hdnPesquisaID.Value
Dim
intFilesRelatorio
As
Integer
= rauRelatorio.UploadedFiles.Count
If
intFilesRelatorio > 0
Then
Try
While
intFilesRelatorio <> 0
Dim
strGuid
As
String
= System.Guid.NewGuid.ToString
Dim
objArquivoPesquisa
As
New
ArquivoPesquisa
With
objArquivoPesquisa
.ArquivoTipo = EnumArquivoPesquisaTipo.Relatorio
.DataCadastro = Now
.NomeGuid = strGuid & rauRelatorio.UploadedFiles.Item(intFilesRelatorio - 1).GetExtension
.NomeOriginal = rauRelatorio.UploadedFiles.Item(intFilesRelatorio - 1).FileName
.PesquisaID = intPesquisaID
End
With
rauRelatorio.UploadedFiles(intFilesRelatorio - 1).SaveAs(strGuid & rauRelatorio.UploadedFiles.Item(intFilesRelatorio - 1).GetExtension)
ArquivoPesquisaFacade.InsertArquivoPesquisa(objArquivoPesquisa)
objArquivoPesquisa =
Nothing
intFilesRelatorio -= 1
End
While
Catch
ex
As
Exception
lblWarning.Text = ex.ToString
lblWarning.Visible =
True
End
Try
End
If
End
Sub
0
Hi Jorge,
the Telerik team
Did you set the TemporaryFileExpiration property? I have created small sample based on the provided code, but there is no such error and the file is renamed correctly after it is copied to the Target folder. Please find the sample attached.
What is your RadAsyncUpload declaration?
Regards,
the Telerik team
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 their blog feed now.
0

Jorge
Top achievements
Rank 1
answered on 04 Apr 2013, 11:39 PM
Thank you! It worked, but after uploading the files, the RadAsyncUpload control doesn't clear the list of files. By list, I mean, the file names that are bounded to the control, and not the temporary files.
0

Jorge
Top achievements
Rank 1
answered on 05 Apr 2013, 10:48 AM
it seems that the button wasn't clearing the list of files bound to RadAsyncUpload, because the button was part of a trigger for a asyncpostback
<asp:AsyncPostBackTrigger ControlID="btnSalvar" EventName="Click" />
So, What I did was to put the RadAsyncUpload inside the UpdatePanel, and now it is being cleared.
Problem solved.
Thanks!
<asp:AsyncPostBackTrigger ControlID="btnSalvar" EventName="Click" />
So, What I did was to put the RadAsyncUpload inside the UpdatePanel, and now it is being cleared.
Problem solved.
Thanks!