Upload file with temporary file never been deleted.

Thread is closed for posting
2 posts, 0 answers
  1. Lin Liu
    Lin Liu avatar
    1 posts
    Member since:
    May 2007

    Posted 11 Jun 2010 Link to this post

    I use uploadedfile.saveas(targetphysicalfolder) (version 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

    <input type="file"

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


    Text=" Upload "




    ToolTip="Click to upload file."







    <td colspan="2">


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



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






    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

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




    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...



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

    Exit Sub

    End If






    "UploadFilePath") & fileName)

    'update database
    'send email notice


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







    Catch ex As Exception




    '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...





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





    "xError.aspx", False)  




    'Set impersonation back to previous user...  







    End Try


    End Sub






  2. Genady Sergeev
    Genady Sergeev avatar
    1600 posts

    Posted 16 Jun 2010 Link to this post

    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.
Back to Top