Fileupload Control无法在Chrome中运行,但适用于IE,ASP.NET

时间:2017-03-05 10:28:49

标签: c# asp.net google-chrome internet-explorer sharepoint

该代码仅适用于IE,因为Chrome只提供文件控制的文件名,而IE则提供完整路径。 如何使它也适用于铬? 我在Sharepoint上传和覆盖附件

    foreach (GridViewRow row in GridView1.Rows)
    {
         if (row.RowType == DataControlRowType.DataRow)
         {
              FileUpload fileUpload = row.Cells[0].FindControl("FileUploadControl") as FileUpload;

              if (fileUpload.HasFile)
              {
                   filePath = fileUpload.PostedFile.FileName;
                   GetUrl(filePath);
              }
         }
     }

     public void GetUrl(string filePath)
        { 
           SPSecurity.RunWithElevatedPrivileges(delegate()
           {
               using (var clientContext = new ClientContext("http:/test/"))
               {
                 using (var fs = new FileStream(filePath, FileMode.Open))
                 {
                   var fi = new FileInfo(filename);
                   var list1 = clientContext.Web.Lists.GetByTitle("Customer");
                   clientContext.Load(list1.RootFolder);
                   clientContext.ExecuteQuery();
                   var fileUrl = String.Format("{0}/Attachments/{1}/{2}", list1.RootFolder.ServerRelativeUrl, ids, fi.Name);
                   Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, fileUrl, fs, true);
                 }
               }
           });                
        }

0 个答案:

没有答案