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

Upload file with temporary file never been deleted.

1 Answer 84 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Lin Liu
Top achievements
Rank 1
Lin Liu asked on 11 Jun 2010, 08:25 PM
I use uploadedfile.saveas(targetphysicalfolder) (version 2.3.2.0) to save file on server, but the temporary file is created in temp folder on server and not automatically deleted ever. It makes spaces on our server reduced and our network staff has to manually deleted them regularly. Is there any way to delete the temporary file immediately after uploading?

Here is my code in VB.Net
.aspx: 

<input type="file"

style="width: 95%"
runat="server"
id="inputFile" /> </td>
<td align="left" colspan="2"> <asp:button id="btnUpload"

 

Text=" Upload "

 

runat="server"

 

ToolTip="Click to upload file."

 

CssClass="Button">

 

</asp:button>

 

</td>

<td colspan="2">

 

<radU:RadProgressManager ID="RadProgressManager1" runat="server" UniquePageIdentifier="eae0adf1-8382-4884-8843-a38bf3b99b38" />  

 

 

<radU:RadProgressArea ID="RadProgressArea1" runat="server">  

 

</radU:RadProgressArea>

 

</td>


.aspx.vb

Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click

 

 

'Store current user token in a variable...

 

 Dim tokenCurrentUser As System.IntPtr = System.Security.Principal.WindowsIdentity.GetCurrent.Token

Try
file = RadUploadContext.Current.UploadedFiles(inputFile.UniqueID)

'validating

 

 

If validating() = False Then

 

 

 

 

Exit Sub

 

End If


fileName = file.GetName

 

 

fileExt = file.GetExtension

 

filesize = file.ContentLength

 

'Impersonate ASPNETRW account ...  

 

 

Dim szASPNETRWPassword As String = Trim(All.DecryptPassWord(Trim(ConfigurationManager.AppSettings("ASPNETRWPassWord"))))

 

 

 

 

If Not ImpersonateUser.ImpersonateValidUser("aspnetrw", "HCA_LAN", szASPNETRWPassword) Then

 

'Notify user of error...

ClientScripts.CallMsgBox(

 

Me, "Error", "Sorry, unable to access archive at this time.")

Exit Sub

End If

 

 

 

file.SaveAs(ConfigurationManager.AppSettings(

 

"UploadFilePath") & fileName)

'update database
NewPHI_Request()
'send email notice

sendMail()

Response.Redirect("xThankyou.aspx", False)

 

 

 

 

 

 

Catch ex As Exception

 

 Try

 

'pass error to web service...

 xLogError.LogError(ex.Message, ex.StackTrace)

 

 

 

Catch exLogError As Exception  

 

End Try

 

 

 

 

'place error message into session and redirect to error page...

Session.Item(

 

 

 

"ErrorMessage") = ex.Message.ToString()

Response.Redirect(

 

 

 

"xError.aspx", False)  

 

Finally  

 

'Set impersonation back to previous user...  

ImpersonateUser.UndoImpersonation()

System.Security.Principal.WindowsIdentity.Impersonate(tokenCurrentUser)

 

 

 

 

End Try

 

End Sub

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 16 Jun 2010, 12:57 PM
Hello Lin Liu,

Indeed, the version that you use may have such problems. In order to get rid of such outstanding issues I suggest that you upgrade to the AJAX version of the controls.

As for the solution for your problem, you can delete the temp files using the File.Delete method. You need to pass the name of the file (along with the path) that you want to delete. Are the files in the temp folder saved with the same  name as in the TargetFolder?

There is another solution for the problem. Don't use RadUploadContext at all. What you can use instead is the .NET Request.Files collection. Here is an example:

 
foreach (HttpPostedFile postedFile in Request.Files)
      {
          Request.Files[postedFile].SaveAs(/* path */);
      }

I hope that this helps.

Kind regards,
Genady Sergeev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Upload (Obsolete)
Asked by
Lin Liu
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Share this question
or