Asp.net 添加ASP:DropDownList以选择ASPxUploadControl的上载文件夹

Asp.net 添加ASP:DropDownList以选择ASPxUploadControl的上载文件夹,asp.net,devexpress,dropdownbox,Asp.net,Devexpress,Dropdownbox,我有一个web表单,它使用DevExpress ASPxUploadControl(v8.3)让用户将文档上传到服务器。我正在开发一个增强功能,允许他们为文档选择一个上传文件夹。这些不是物理文件夹,而是逻辑文件夹。我在表单中添加了一个ASP:DropDownList,我使用用户设置的文件夹的名称从数据库中填充它。如果用户选择文件夹和附件,则一切正常。但是,如果他们先选择要上载的文件,然后选择文件夹,则在选择文件后会自动上载该文件,而不是等待他们单击上载链接。如果他们选择了错误的文档,这不允许他们

我有一个web表单,它使用DevExpress ASPxUploadControl(v8.3)让用户将文档上传到服务器。我正在开发一个增强功能,允许他们为文档选择一个上传文件夹。这些不是物理文件夹,而是逻辑文件夹。我在表单中添加了一个ASP:DropDownList,我使用用户设置的文件夹的名称从数据库中填充它。如果用户选择文件夹和附件,则一切正常。但是,如果他们先选择要上载的文件,然后选择文件夹,则在选择文件后会自动上载该文件,而不是等待他们单击上载链接。如果他们选择了错误的文档,这不允许他们更改。此外,还使用了从dropdownlist中选择的旧(上一个)值—它没有更新以反映新的选择—我怀疑服务器端事件和客户端事件之间存在冲突。以下是相关代码。如何防止页面自动上载文档

谢谢! 迈克


允许的文件类型:jpeg、gif、pdf、rtf、doc、docx、txt、csv、xls、xlsx、wav
最大文件大小:4Mb
私有的
(检查私人文件可防止管理公司和助理通过客户端查看附件。)
登录。)
受保护的子页加载(ByVal sender作为对象,ByVal e作为System.EventArgs)处理Me.Load
Dim DAL作为新的数据访问层
将DTF文件夹设置为新数据表
LoadData(会话(“UserPKey”))
会话(“当前页面”)=“CaseAttchmt.aspx”
如果Session(“LoggedOn”)=True且GlobalVar.ConnectString为“”,则
CSSDefaultHTML=会话(“CSS_默认值”)
DefaultIPHTML=应用程序(“DefaultIP”)
如果结束
SelKey=Request.QueryString(“Case”)
Header1.ConnectionStr=GlobalVar.ConnectString
Header1.HDLawFirm=GlobalVar.LawFirmDir
Header1.InsertHeader(“将文件添加到案例中”,0,0,SelKey,“宽度=100%对齐=中心”)
ClientKey=会话(“ClientKey”)
UploadDirectory=GlobalVar.LawFirmDir&“AttachFiles/Case”&Trim(Str(SelKey))&//
如果System.IO.Directory.Exists(GlobalVar.LawFirmDir&“AttachFiles/”)=False,则
System.IO.Directory.CreateDirectory(GlobalVar.LawFirmDir和“附件”)
如果结束
如果System.IO.Directory.Exists(GlobalVar.LawFirmDir&“AttachFiles/Case”&Trim(Str(SelKey))=False,则
System.IO.Directory.CreateDirectory(GlobalVar.LawFirmDir&“AttachFiles/Case”和Trim(Str(SelKey)))
如果结束
保存数据(会话(“UserPKey”))
dtFolders=DAL.GetClientFolders(会话(“ClientKey”))
ddlFolders.DataSource=dtFolders
将文件夹设置为列表项
作为整数的Dim i
将整数值设置为整数
将strText设置为字符串
如果不是Page.IsPostBack,则
ddlFolders.Items.Clear
intValue=0
strText=“附件”
lstFolders=新列表项(strText,intValue)
ddlFolders.Items.Add(lstFolders)
对于i=0到dtFolders.Rows.Count-1
intValue=dtFolders.Rows(i).Item(“pKey”)
strText=dtFolders.Rows(i).Item(“FolderName”)
lstFolders=新列表项(strText,intValue)
ddlFolders.Items.Add(lstFolders)
下一个
ddlFolders.SelectedIndex=0
会话(“FolderKey”)=0
如果结束
端接头
受保护的函数SavePostedFile()为字符串
Dim filename As String=“”
Dim TEMPFILNAME As String=“”
SelKey=会话(“SelKey”)
如果Len(Trim(Session(“ClientKey”))=4,则
UploadDirectory=“~/DATA/AR00”&Session(“ClientKey”)和“/AttachFiles/Case”&Trim(Str(SelKey))&”/
其他的
UploadDirectory=“~/DATA/”&Trim(Session(“LawFirm”)&“/AttachFiles/Case”&Trim(Str(SelKey))&/”
如果结束
filename=Trim(upimage.filename)
如果文件名为“”,则
tempFileName=MapPath(上传目录)&filename
upimage.SaveAs(tempFileName)
如果结束
返回临时文件名
端函数
受保护的子上传映像\u文件上传完成(ByVal发送方作为对象,ByVal e作为文件上传完成对象)
Dim文件以布尔值=False的形式存在
UploadDirectory=“~/DATA/”&Trim(Session(“LawFirm”)&“/AttachFiles/Case”&Trim(Str(Session(“SelKey”))&/”
Dim FilePath作为String=MapPath(UploadDirectory)和Trim(upimage.FileName)
FileExists=CheckForFile(FilePath)
'urk:2010年1月6日,添加了检查上传文件名长度和文件大小的验证。
如果(e.IsValid)那么
如果(e.UploadedFile.FileName.Length>100),则
e、 ErrorText=“文件名长度不能超过100个字符。请缩短并重试。”
ElseIf(e.UploadedFile.FileName.Contains(“'))或e.UploadedFile.FileName.Contains(“&”))然后
e、 ErrorText=“文件名不能包含撇号或符号和字符。”
ElseIf(e.UploadedFile.FileName.EndsWith(“.aspx”))或(e.UploadedFile.FileName.EndsWith(“.aspx”)
<td class="style6" valign="middle">
                &nbsp;&nbsp;<asp:Panel ID="Panel3" colspan="2" runat="server" Height="83px" Width="125px"
                    Style="margin-top: 0px">
                                <dxuc:ASPxUploadControl ID="uplImage" runat="server" 
                                ClientInstanceName="uploader" Font-Size="Medium" Height="84px" 
                                OnFileUploadComplete="uplImage_FileUploadComplete" ShowUploadButton="True" 
                                Size="50" style="margin-top: 0px; margin-right: 2px;">

                                    <ValidationSettings AllowedContentTypes="image/jpeg,image/gif,image/pjpeg,application/pdf,application/rtf,application/msword,application/vnd.ms-excel,application/csv,text/plain,text/csv,text/richtext,text/rtf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, audio/wav" MaxFileSize="4096000">
                                        <ErrorStyle Font-Size="Smaller" />
                                    </ValidationSettings>
                                    <ClientSideEvents FileUploadComplete="function(s, e) {
                            if(e.isValid)
                            {
                                if(e.errorText != ''){
                                    alert(e.errorText);
                                } else {
                                    alert(e.callbackData);
                                }
                            }
                        }" />
                        <ValidationSettings AllowedContentTypes="image/jpeg, image/gif, image/pjpeg, application/pdf, application/rtf, application/msword, application/vnd.ms-excel, application/csv, text/plain, text/csv, text/richtext, text/rtf, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, audio/wav"
                            MaxFileSize="4096000">
                            <ErrorStyle Font-Size="Smaller" />
                        </ValidationSettings>
                                    <ClientSideEvents FilesUploadComplete="function(s, e) {}" FileUploadComplete="function(s, e) {
                            if(e.isValid)
                            {
                                if(e.errorText != ''){
                                    alert(e.errorText);
                                } else {
                                    alert(e.callbackData);
                                }
                            }
                        }" FileUploadStart="function(s, e) {}" />

                    </dxuc:ASPxUploadControl>

                </asp:Panel>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td colspan="2" class="txtnote" align="center" style="height: 18px">
                Allowed file types: jpeg, gif, pdf, rtf, doc, docx, txt, csv, xls, xlsx, wav
            </td>
        </tr>
        <tr>
            <td colspan="2" class="txtnote" align="center" style="height: 10px">
                Maximum file size: 4Mb
            </td>
        </tr>
        <tr>
        <td></td>
        <td>
            <input id="chkPrivate" name="chkPrivate"  value="1" type="checkbox"/>Private 
            (checking Private prevents Mgmt Co &amp;Assn from viewing attachment via client 
            login.)</td></tr>            
        <tr class="aligncenter">
            <th class="style5" align="center" colspan="2">
                &nbsp;</th>
        </tr>
        <tr class="aligncenter">
            <th class="style5" align="center" colspan="2">
                <asp:Panel ID="Panel2" runat="server" Height="50px" Width="125px">
                    <%--<dxe:ASPxButton ID="Button1" runat="server" Font-Size="Medium" Text="Cancel">
                        <Paddings PaddingLeft="10px" PaddingRight="10px" />
                    </dxe:ASPxButton>--%>
                    <input type="button" id="btnReturn" class="frmBtnCommon" value="Back To Case" onclick="ReturnToCase();" />
                </asp:Panel>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim DAL As New DataAccessLayer
        Dim dtFolders As New DataTable

        GlobalVar.LoadData(Session("UserPKey"))

        Session("CurrentPage") = "CaseAttchmt.aspx"
        If Session("LoggedOn") = True And GlobalVar.ConnectString <> "" Then
            CSSDefaultHTML = Session("CSS_Default")
            DefaultIPHTML = Application("DefaultIP")
        End If

        SelKey = Request.QueryString("Case")

        Header1.ConnectionStr = GlobalVar.ConnectString
        Header1.HDLawFirm = GlobalVar.LawFirmDir
        Header1.InsertHeader("Add File to a Case", 0, 0, SelKey, "width=100% align=center")
        ClientKey = Session("ClientKey")
        UploadDirectory = GlobalVar.LawFirmDir & "AttachFiles/Case" & Trim(Str(SelKey)) & "/"

        If System.IO.Directory.Exists(GlobalVar.LawFirmDir & "AttachFiles/") = False Then
            System.IO.Directory.CreateDirectory(GlobalVar.LawFirmDir & "AttachFiles")
        End If

        If System.IO.Directory.Exists(GlobalVar.LawFirmDir & "AttachFiles/Case" & Trim(Str(SelKey))) = False Then
            System.IO.Directory.CreateDirectory(GlobalVar.LawFirmDir & "AttachFiles/Case" & Trim(Str(SelKey)))
        End If

        GlobalVar.SaveData(Session("UserPKey"))

        dtFolders = DAL.GetClientFolders(Session("ClientKey"))
        ddlFolders.DataSource = dtFolders
        Dim lstFolders As ListItem
        Dim i As Integer
        Dim intValue As Integer
        Dim strText As String

        If Not Page.IsPostBack Then
            ddlFolders.Items.Clear
            intValue = 0
            strText = "Attachments"
            lstFolders = New ListItem(strText, intValue)
            ddlFolders.Items.Add(lstFolders)

            For i = 0 to dtFolders.Rows.Count - 1
                intValue = dtFolders.Rows(i).Item("pKey")
                strText = dtFolders.Rows(i).Item("FolderName")
                lstFolders = New ListItem(strText, intValue)
                ddlFolders.Items.Add(lstFolders)
            Next
            ddlFolders.SelectedIndex = 0
            Session("FolderKey") = 0
        End If

    End Sub

    Protected Function SavePostedFile() As String

        Dim filename As String = ""
        Dim tempFileName As String = ""
        SelKey = Session("SelKey")
        If Len(Trim(Session("ClientKey"))) = 4 then
            UploadDirectory = "~/DATA/AR00" & Session("ClientKey") & "/AttachFiles/Case" & Trim(Str(SelKey)) & "/"
        Else
            UploadDirectory = "~/DATA/" & Trim(Session("LawFirm")) & "/AttachFiles/Case" & Trim(Str(SelKey)) & "/"
        End If

        filename = Trim(uplImage.FileName)

        If filename <> "" Then
            tempFileName = MapPath(UploadDirectory) & filename
            uplImage.SaveAs(tempFileName)
        End If
        Return tempFileName

    End Function

    Protected Sub uplImage_FileUploadComplete(ByVal sender As Object, ByVal e As FileUploadCompleteEventArgs)

        Dim FileExists As Boolean = False
        UploadDirectory = "~/DATA/" & Trim(Session("LawFirm")) & "/AttachFiles/Case" & Trim(Str(Session("SelKey"))) & "/"

        Dim FilePath As String = MapPath(UploadDirectory) & Trim(uplImage.FileName)

        FileExists = CheckForFile(FilePath)

        'urk : Added validation for checking filename length and filesize being uploaded 06/01/2010.
        If (e.IsValid) Then
            If (e.UploadedFile.FileName.Length > 100) Then
                e.ErrorText = "The file name cannot be more than 100 characters long.  Please shorten and retry."
            ElseIf (e.UploadedFile.FileName.Contains("'") Or e.UploadedFile.FileName.Contains("&")) Then
                e.ErrorText = "The file name cannot contain the apostrophe or ampersand characters."
            ElseIf (e.UploadedFile.FileName.EndsWith(".aspx")) Or (e.UploadedFile.FileName.EndsWith(".ASPX")) Then
                e.ErrorText = ".aspx files are not allowed for upload."
            ElseIf FileExists = True Then
                e.ErrorText = "A file with this name has already been uploaded.  Please rename and try again."
            Else
                e.CallbackData = SavePostedFile()
                If e.CallbackData <> "" Then
                    s_UpdateAttachData()
                End If
                e.CallbackData = "File: '" + e.UploadedFile.FileName + "' uploaded successfully."
            End If
        End If

    End Sub

    Private Sub s_UpdateAttachData()

        Dim i_date As DateTime = Now.Date
        Dim DAL As New DataAccessLayer

        ClientKey = Session("ClientKey")
        Dim pPrintBy As Integer = Session("UserPKey")
        Dim PrintDate As DateTime = Now
        Dim s As Boolean
        Dim FullAttchPath As String

        If Len(trim(ClientKey)) = 1 Then
            FullAttchPath = "DATA/AR00000" + ClientKey.ToString + "/AttachFiles/Case" + SelKey.ToString + "/" + Trim(uplImage.FileName)
        ElseIf Len(Trim(ClientKey)) = 4 then
            FullAttchPath = "DATA/AR00" + ClientKey.ToString + "/AttachFiles/Case" + SelKey.ToString + "/" + Trim(uplImage.FileName)
        Else
            FullAttchPath = "DATA/AR0" + ClientKey.ToString + "/AttachFiles/Case" + SelKey.ToString + "/" + Trim(uplImage.FileName)
        End If
        If Request.Form("chkPrivate") <> "" Then
            s = 1
        Else
            s = 0
        End If

        DAL.InsertCasesAttachPKey(ClientKey, SelKey, Trim(uplImage.FileName), Trim(uplImage.FileName), pPrintBy, PrintDate, s, FullAttchPath, Session("FolderKey"))

    End Sub

    Protected Function CheckForFile(ByVal Filename As String) As Boolean

        If File.Exists(Filename) Then
            Return True
        Else
            Return False
        End If

    End Function

        Protected Sub ddlFolders_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ddlFolders.SelectedIndexChanged

        Session("FolderKey") = ddlFolders.SelectedValue

    End Sub