防止在输入类型文件中在回发时丢失所选文件

时间:2016-02-23 12:05:14

标签: javascript c# asp-classic

这是我的代码,其中我从用户输入两个文件。第二个文件的输入取决于选择的第一个文件的扩展名我决定是否接受第二个文件输入。所有决定采取第二个文件输入很好,但发回后第一个文件输入丢失其选定的文件..请帮助我如何防止在表单提交后丢失第一个文件选择。 这是我的aspx页面代码

   <tr bgcolor="white" id="tr_SourceFile"  runat="server">
                        <td style="height: 20px">
                            Source File
                        </td>
                        <td>
                            <input class="body_text" type="file"  ClientIDMode="Static" onchange="this.form.submit()" id="src_File" name="src_File" runat="server"
                                style="width: 420px" />
                        </td>
                    </tr> 
                <%if (ShowCompileAttach) 
                  {%>
                     <tr bgcolor="white" id="tr_CompileFile" runat="server"> 
                        <td style="height: 20px">
                            Compiled File
                        </td>
                        <td style="height: 16px; width: 625px;">
                            <input class="body_text" type="file" id="comp_File" runat="server" style="width: 420px" />
                        </td>
                    </tr>

                  <%} %>  

这是我的.CS代码

if (IsPostBack && src_File.PostedFile != null)
        {
            if (src_File.PostedFile.FileName.Length > 0)
            {
                OnFileUpload();
            }
        }
  static NameValueCollection sourceFilesExt;
    public void OnFileUpload() 
    {
        string srcFile = src_File.Value;
        if (isReportSourceFile(srcFile, vr_flag))
        {
            ShowCompileAttach = false;
        }
        else 
        {
            ShowCompileAttach = true;
        }
    }
    public static bool isReportSourceFile(string fileName, int vr_flag)
    {
        try
        {
            if (IO.getFileExtension(fileName.ToLower()) == ".rdf")
                {

                    return true;
                }

            return false;
        }
        catch
        {
            return false;
        }
    }

            I can't use asp:Fileuploader as I am working on .net 2.0   

0 个答案:

没有答案