Uploaded file gets deleted on redirect to new page

  •  05-19-2010, 12:38 PM

    Uploaded file gets deleted on redirect to new page

    I am in the middle of building a DotNetNuke Portal and have built a File Upload module using the Ajax Uploader. The code is relatively simple, and is almost the same as the samples. What happens though is once the file is uploaded and copied to the folder where I want it saved, a redirect to the next page occurs and the FILE GETS DELETED. Not the persisted, file, the file I want saved that was copied using the args.CopyTo method.
     
    One thing I have noticed, if I do a copyTo with the name of the file as uploaded, the file saves and persists in our upload folder, if I do a file rename in the copyTo method to the name of the file that we want the file named to so we guarantee uniqueness, the file gets deleted when navigating to the next page.
     
    I am running IIS 7.5 on Window 7 for development with SQL Server 2008
     
    I have the basic entries in the web.config file (with the ones in http modules listed first above the DNN references and in appSettings have the following:
     
    <add key="CuteWebUI.AjaxUploader.GlobalMaxSizeKB" value="100000"/>
    <add key="CuteWebUI.AjaxUploader.TempDirectory" value="~/Portals/0/Temp"/>
     
     
     HTML is below:
     
    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="FileUpload.ascx.vb" Inherits="GPP.Controls.FileUpload" %>
    <style type="text/css">
        .upload_button { background-image: url(/DesktopModules/GPP_FileUpload/images/upload.gif); background-repeat: no-repeat; height: 22px; width: 80px; }
    </style>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <div>
                <div style="padding-bottom: 15px; width: 420px; font-size: 13px; font-family: Arial, Verdana, Sans-Serif;">
                    Click the Browse button below, select the picture on your computer that you want converted to a poster and the file will be uploaded to our server.
                </div>
                <div>
                    <CuteWebUI:Uploader ID="ctlUploader" UploadType="Auto" runat="server" InsertText="" InsertButtonStyle-BorderStyle="None" InsertButtonStyle-BackColor="Transparent" InsertButtonStyle-CssClass="upload_button" ProgressPanelWidth="400" MaxFilesLimit="1" ShowFrameBrowseButton="false">
                    </CuteWebUI:Uploader>
                </div>
            </div>
            </asp:Panel>
        </ContentTemplate>
    </asp:UpdatePanel>


    Code Behind: 
     
    Imports DotNetNuke

    Namespace GPP.Controls
        Partial Class FileUpload
            Inherits Entities.Modules.PortalModuleBase

            Protected Sub ctlUploader_UploadCompleted(ByVal sender As Object, ByVal args() As CuteWebUI.UploaderEventArgs) Handles ctlUploader.UploadCompleted
                Dim strExt As String = Mid(args(0).FileName, InStrRev(args(0).FileName, ".", , CompareMethod.Text))
                Dim strFileName As String = System.Guid.NewGuid.ToString()
                Dim strFileGuid As String = strFileName & strExt

                ' Save Image info to the database and gets back other info
                Dim ds As DataSet = GPP_Procedures.GPP_ProceduresController.SaveImage(UserId, Session.SessionID, strFileGuid)
                Using ds
                    strFileGuid = ds.Tables(0).Rows(0).Item("ImageName")
                    Session("CartGuid") = ds.Tables(0).Rows(0).Item("ShoppingCartGUID")
                    Session("FileGuid") = ds.Tables(0).Rows(0).Item("ShoppingCartImageGUID")
                End Using
                args(0).CopyTo(Server.MapPath("~/Portals/0/Uploads/" & strFileGuid))
                Response.Redirect("~/Processing.aspx", True)
            End Sub
        End Class
    End Namespace

    Everything seems to work fine, step through the code and file gets uploaded, saved and then when the redirect occurs, the saved file gets deleted and the persisted file in the temp folder remains. I have tried this as a stand alone file as well (thinking of running in an IFrame) but same results.
     
     
View Complete Thread