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

     

     

     

     

     

  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top