Database Identity Seed

6 posts, 0 answers
  1. Jorge
    Jorge avatar
    4 posts
    Member since:
    Sep 2011

    Posted 27 Mar 2013 Link to this post

    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
  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 29 Mar 2013 Link to this post

    Hello Jorge,

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jorge
    Jorge avatar
    4 posts
    Member since:
    Sep 2011

    Posted 01 Apr 2013 Link to this post

    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.

    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
  5. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 04 Apr 2013 Link to this post

    Hi Jorge,

    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,

    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.
  6. Jorge
    Jorge avatar
    4 posts
    Member since:
    Sep 2011

    Posted 04 Apr 2013 Link to this post

    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.
  7. Jorge
    Jorge avatar
    4 posts
    Member since:
    Sep 2011

    Posted 05 Apr 2013 Link to this post

    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!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017