2016-07-26 69 views
0

在c#net 4.0中保存页面信息后,我需要在多种模式下添加一些图片。在c#net 4.0中多次上传

我不能使用净4.5。

问题:

如果我打开一个浏览器IE 11这个工作正常多个上传页面,您可以选择多个图片上传。

如果我在IE 11的弹出窗口中打开多个上载的同一页面,则无法选择多张图片上传,而只能选择一张图片。

有什么问题?

我的代码如下,提前谢谢。

的.aspx标记(Default.aspx的)

<form id="form1" runat="server"> 
    <div> 

     <asp:Panel ID="upload01" runat="server" CssClass="pure-form pure-form-stacked"> 
      <fieldset style="margin-left: 50px"> 
       <legend style="font-weight: bold; color: Red; margin-left: 10px;">PICS</legend> 
       <div class="pure-g"> 
        <div class="pure-u-1 pure-u-md-1-3"> 
         <label for="Pics">Pics</label> 

         <p> 
          <asp:FileUpload ID="fileUpload" multiple="true" runat="server" /> 
         </p> 
         <p> 
          <p> 
           <asp:Button ID="btUpload" Text="Upload Files" 
            OnClick="Upload_Files" runat="server" /> 
          </p> 
         </p> 
         <p> 
          <asp:Label ID="lblFileList" runat="server"></asp:Label> 
         </p> 
         <p> 
          <asp:Label ID="lblUploadStatus" runat="server"></asp:Label> 
         </p> 
         <p> 
          <asp:Label ID="lblFailedStatus" runat="server"></asp:Label> 
         </p> 

        </div> 
       </div> 
      </fieldset> 
      </asp:Panel> 
    </div> 
</form> 

的.cs代码隐藏

protected void btnSave_Click(object sender, ImageClickEventArgs e) 
{ 
    ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "var Mleft = (screen.width/2)-(760/2);var Mtop = (screen.height/2)-(700/2);window.open('Default.aspx', null, 'height=700,width=760,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,top=\'+Mtop+\', left=\'+Mleft+\'');", true); 
} 

EDIT#1

protected void Upload_Files(object sender, EventArgs e) 
    { 
     if (upload01.HasFile)  // CHECK IF ANY FILE HAS BEEN SELECTED. 
     { 
      int iUploadedCnt = 0; 
      int iFailedCnt = 0; 
      HttpFileCollection hfc = Request.Files; 
      lblFileList.Text = "Select <b>" + hfc.Count + "</b> file(s)"; 

      if (hfc.Count <= 10) // 10 FILES RESTRICTION. 
      { 
       for (int i = 0; i <= hfc.Count - 1; i++) 
       { 
        HttpPostedFile hpf = hfc[i]; 
        if (hpf.ContentLength > 0) 
        { 
         if (!File.Exists(Server.MapPath("\\images\\") + 
          Path.GetFileName(hpf.FileName))) 
         { 
          DirectoryInfo objDir = 
           new DirectoryInfo(Server.MapPath("\\images\\")); 

          string sFileName = Path.GetFileName(hpf.FileName); 
          string sFileExt = Path.GetExtension(hpf.FileName); 

          // CHECK FOR DUPLICATE FILES. 
          FileInfo[] objFI = 
           objDir.GetFiles(sFileName.Replace(sFileExt, "") + ".*"); 

          if (objFI.Length > 0) 
          { 
           // CHECK IF FILE WITH THE SAME NAME EXISTS (IGNORING THE EXTENTIONS). 
           foreach (FileInfo file in objFI) 
           { 
            string sFileName1 = objFI[0].Name; 
            string sFileExt1 = Path.GetExtension(objFI[0].Name); 

            if (sFileName1.Replace(sFileExt1, "") == 
              sFileName.Replace(sFileExt, "")) 
            { 
             iFailedCnt += 1;  // NOT ALLOWING DUPLICATE. 
             break; 
            } 
           } 
          } 
          else 
          { 
           // SAVE THE FILE IN A FOLDER. 
           hpf.SaveAs(Server.MapPath("\\images\\") + 
            Path.GetFileName(hpf.FileName)); 
           iUploadedCnt += 1; 
          } 
         } 
        } 
       } 
       lblUploadStatus.Text = "<b>" + iUploadedCnt + "</b> file(s) Uploaded."; 
       lblFailedStatus.Text = "<b>" + iFailedCnt + 
        "</b> duplicate file(s) could not be uploaded."; 
      } 
      else lblUploadStatus.Text = "Max. 10 files allowed."; 
     } 
     else lblUploadStatus.Text = "No files selected."; 
    } 
+0

Upload_Files中有什么? – BugFinder

+0

@BugFinder嗨,谢谢请参阅**编辑#1 **在我的第一个问题。 –

回答

1

我薄k你的方法对于这个问题是错误的

请看这个,我希望这个帮助。

Click here