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

Read the Temporary file name

7 Answers 276 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Tony
Top achievements
Rank 1
Tony asked on 03 Jul 2013, 03:54 PM
Hi, I need to read the temporary filename that RadAsyncUpload has used.

I have tried the following:

protected void AttachmentAsyncUpload_OnFileUploaded(object sender, FileUploadedEventArgs e)
        {
            string targetFolder = ((RadAsyncUpload)sender).TargetFolder;
            Response.Write(Server.MapPath(targetFolder + "/" + e.File.FileName));
        }

but this is not returning the filename on the disk - I need the full temp file name for example: 1372860982657testdoc.jpg and not just testdoc.jpg

My understanding is that the files are not cleared by default for 4 hours and I need to be able to read the file contents after several postbacks so need to know the temp filenames.

Thanks
Tony

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 04 Jul 2013, 05:52 AM
Hi Tony,

Based on this forum thread, The temporary filename is not available on the client due to security reasons. The server side code you tried does not return the Temporary file name. In that code Server.MapPath(targetFolder + "/" + e.File.FileName) statement provides the final path of the uploaded file on the server.
Finally, all processed temporary files are deleted. Temporary files are also deleted after a set amount of time defined by the TemporaryFileExpiration property. If this property is not set, it will be deleted automatically by the .NET framework after 4 hours.

Thanks,
Shinu.
0
Tony
Top achievements
Rank 1
answered on 04 Jul 2013, 08:40 AM
to be clear - I need to read the temporary filename server-side via c#

If I iterate the RadAsyncUpload.UploadedFiles list I can see properties of the files and would normally use the

InputStream to read the file and save but I don't want to save the file at this point - I need the temp filename.

Using the debugger I expanded non-public members and can see a property TempFilePath  - this has the full path and the temporary filename I need - is there a way (without reflection) to access this property?


Thanks
Tony
0
Plamen
Telerik team
answered on 09 Jul 2013, 05:35 AM
Hello Tony,

 
Basically Temporary file directory is used only internally in RadAsyncUpload and the files in it should not be modified and that is why they can not be used from the server. 

Would you please elaborate what exactly are you trying to achieve so we could be more helpful with a possible solution?

Regards,
Plamen
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
Tony
Top achievements
Rank 1
answered on 09 Jul 2013, 01:19 PM
Hi Plamen

I'm using the asp.net wizard control and on step 3 of 4 I have a RadGrid with the AsyncUpload control as part of the grid.

When the grid row is saved the form posts back but I dont save the file - I just want to keep a reference to the temporary file name - this appears to be saved with a unique filename which I had planned to use when the wizard is complete?

Thanks
Tony
0
Accepted
Plamen
Telerik team
answered on 11 Jul 2013, 03:23 PM
Hi Tony,

 
Thank you for elaborating the issue. 

Unfortunately such behavior is not supported by RadAsyncUpload.  
The only possible workaround is to persist the uploaded files-please have in mind that this is possible only if the control is rendered on the page.

Hope this will explain the issue.

Regards,
Plamen
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
Johann
Top achievements
Rank 1
answered on 12 Feb 2015, 04:58 PM
i had the same problem and i could solve it.

foreach(UploadedFile file in rauUploadFiles.UploadedFiles)
            {
                FileStream tmpFile = (FileStream) file.InputStream;
                images = Directory.GetFiles(HttpContext.Current.Server.MapPath("~/temp")).Where(f => f.Equals(tmpFile.Name)).ToList();
            }

I hope this helps
0
Hamada
Top achievements
Rank 1
answered on 28 Jun 2017, 04:43 PM

you Dont need to worry about the temperate file name , you can download the selected file into Database (and have a special field as temp download) , if you have a wizard then you can save it permanently later on  (Change the temp field indicator)  , I have this full example how to use the RadAsyncUpload and save it into a database , Thanks Telerik to make it easy: 

----- RadAsyncUpload

<telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" MultipleFileSelection="Automatic" PostbackTriggers="RadButton_Upload" RenderMode="Lightweight" ToolTip="Select to Upload Documents for this customer">
                    </telerik:RadAsyncUpload>

 

<telerik:RadButton ID="RadButton_Upload" runat="server" SingleClick="True" Text="Upload File(s)">
                    </telerik:RadButton>

 

------ database 

[FileName] [varchar](max) NULL,
[FileType] [varchar](max) NULL,
[FileSize] [varchar](50) NULL,
[FileExtension] [varchar](50) NULL,
[Added_Date] [datetime] NULL,
[Added_User] [int] NULL,
[RawDataVarbinary] [varbinary](max) NULL,
[LastModify] [datetime] NULL

-------vb.net code 

Private Sub RadAsyncUpload1_FileUploaded(sender As Object, e As FileUploadedEventArgs) Handles RadAsyncUpload1.FileUploaded
    Dim Get_user_ID As String = Page.User.Identity.Name
         Dim fileStream As Stream = e.File.InputStream
         Dim attachmentBytes As Byte() = New Byte(fileStream.Length - 1) {} 'RawData
         fileStream.Read(attachmentBytes, 0, Convert.ToInt32(fileStream.Length))
 
         Dim Myconnectionstring As String = Web.Configuration.WebConfigurationManager.ConnectionStrings("YourDatabaseString").ConnectionString
         Dim MyConnection As New SqlConnection(Myconnectionstring)
         Dim SQL_text As String
         Dim RecordCount As Integer
         Dim MyReader As SqlDataReader
 
         SQL_text = "INSERT INTO filesTable " '
         SQL_text = SQL_text & "(FileName"
         SQL_text = SQL_text & ",FileType"
         SQL_text = SQL_text & ",FileSize"
         SQL_text = SQL_text & ",Added_Date"
         SQL_text = SQL_text & ",Added_User"
         SQL_text = SQL_text & ",FileExtension"
         SQL_text = SQL_text & ",LastModify"
 
         SQL_text = SQL_text & ",RawDataVarbinary)"
         SQL_text = SQL_text & " Values ("
         SQL_text = SQL_text & "'" & e.UploadResult.FileName.ToString & "'," ' file name
         SQL_text = SQL_text & "'" & e.UploadResult.ContentType.ToString & "'," ' type
         SQL_text = SQL_text & "'" & e.UploadResult.ContentLength.ToString & "'," ' size
         SQL_text = SQL_text & "'" & DateTime.Now & "',"
         SQL_text = SQL_text & "'" & Get_user_ID & "'," ' added by user ID
         SQL_text = SQL_text & "'" & e.File.GetExtension.ToString & "'," ' File Extension
         SQL_text = SQL_text & "'" & e.File.LastModifiedDate & "'," ' Last Modify date Time
 
         SQL_text = SQL_text & "@RawData)"
 
         Dim MySelectCm As New SqlCommand(SQL_text, MyConnection)
         MySelectCm.Parameters.AddWithValue("@RawData", attachmentBytes)
 
         MyConnection.Open()
         RecordCount = MySelectCm.ExecuteScalar ' add
        MyConnection.Close()
        
 End Sub

 

Tags
AsyncUpload
Asked by
Tony
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Tony
Top achievements
Rank 1
Plamen
Telerik team
Johann
Top achievements
Rank 1
Hamada
Top achievements
Rank 1
Share this question
or