Setting New Filename Outside of _FileUploaded

3 posts, 0 answers
  1. David
    David avatar
    3 posts
    Member since:
    Jul 2010

    Posted 29 Jul 2010 Link to this post

    Hi,

    I have a RadAsyncUpload control on my page used for a simple 'email' type functionality where a user can attach documents to a message. Snippet On button click to send the message my workflow is this...

    1. Save the message to a database and return the id of the message
    2. Save the recipients of the of the message using the id that is returned from the above function.
    3. I then save each attachment to the db passing in the message id and return the full path of where the file should be saved (looking like this : blah/foo/blah/de/blah/6F9619FF-8B86-D011-B42D-00C04FC964FF.pdf)

    My problem is re-naming the file to the guid passed back as the from what i can see the _FileUploaded event (where i can perform this function) fires before my button click event.

    Any ideas?
  2. Lenny_shp
    Lenny_shp avatar
    343 posts
    Member since:
    Jul 2006

    Posted 29 Jul 2010 Link to this post

    Your solution doesn't seem to work for more than 1 attachment.

    In the postback (final submit) you can do something like this and don't need code in _FileUploaded:  (customize to fit your needs)

     For Each file As Telerik.Web.UI.UploadedFile In myUpload.UploadedFiles
                    Dim strGUID As String
                    strGUID = Guid.NewGuid.ToString
                    Dim strOriginalFileName As String = file.GetName '.Replace("'", "").Replace("&", "and")
                    Dim strFileGUIDName As String = strGUID & "_" & strOriginalFileName
                    Dim strFileFullPath As String = Path.Combine(strUploadPath, strFileGUIDName)

                    Using Hosting.HostingEnvironment.Impersonate
                        file.SaveAs(strFileFullPath, True)
                    End Using
    Next
  3. David
    David avatar
    3 posts
    Member since:
    Jul 2010

    Posted 29 Jul 2010 Link to this post


Back to Top