该代码仅适用于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);
}
}
});
}