2016-07-26 65 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