2010-05-11 99 views

回答

0

我使用jquery MultiFile腳本。
加入jQuery和你的頁面多文件腳本引用後,你會那麼文件輸入添加到您的形式,並通過上傳的文件設置類=「多」

<input type="file" width="50" id="fileUpload" class="multi" runat="server" /> 

在回發,我迭代和保存他們到服務器或雲或任何地方的目錄。

  for (int i = 0; i < Request.Files.Count; i++) 
      { 
       if (Request.Files[i].ContentLength > 0) 
       { 
        int retVal = saveFile((HttpPostedFile)Request.Files[i]); 
        if (retVal != -1) 
         documentID.Add(retVal); // documentID is a list of ID in my sql database. This code is located in a user control for document management. 
       } 
      } 

    // note I have a few utility methods here... 
    private int saveFile(HttpPostedFile file) 
    { 
     if (file.ContentLength > 0) 
     { 
      string directory = Server.MapPath(SiteRoot + UploadURL); 
      string directory_filename_uploaded = directory + file.FileName.Substring(file.FileName.LastIndexOf("\\") + 1); 

      // make sure its unique so we don't overwrite. 
      string directory_filename_unique = Document.GetUniqueFilename(directory_filename_uploaded); 
      string filename_unique = directory_filename_unique.Substring(directory_filename_unique.LastIndexOf("\\") + 1); 

      file.SaveAs(directory_filename_unique); 
      return insertFile(filename_unique); 
     } 
     else 
      return -1; 
    }