我正在尝试将多个文件上传到文档库并更新其列值。List(Doc Lib) 已经存在,但我坚持使用 uploadinf 文件
我试过这些方法
使用 list.asmx
NetworkCredential credentials = new NetworkCredential("user", "Pass", "domain"); #region ListWebService ListService.Lists listService = new ListService.Lists(); listService.Credentials = credentials; List list = cc.Web.Lists.GetByTitle(library); listService.Url = cc.Url + "/_vti_bin/lists.asmx"; try { FileStream fStream = System.IO.File.OpenRead(filePath); string fName = fStream.Name.Substring(3); byte[] contents = new byte[fStream.Length]; fStream.Read(contents, 0, (int)fStream.Length); fStream.Close(); string attach = listService.AddAttachment(library, itemId.ToString(), Path.GetFileName(filePath), contents); } #endregion catch (System.Web.Services.Protocols.SoapException ex) { CSVWriter("Message:\n" + ex.Message + "\nDetail:\n" + ex.Detail.InnerText + "\nStackTrace:\n" + ex.StackTrace, LogReport); }
ServerException :To add an item to a document library, use SPFileCollection.Add()
它给出了一个错误AddAttachment()
使用
List lib = cc.Web.Lists.GetByTitle("TestLib"); FileCreationInformation fileInfo = new FileCreationInformation(); fileInfo.Content = System.IO.File.ReadAllBytes("C:\\Users\\AJohn\\Desktop\\sample.docx"); fileInfo.Url = "https://serverm/sites/Testing1/TestLib/sample.docx"; fileInfo.Overwrite = true; Microsoft.SharePoint.Client.File upFile = lib.RootFolder.Files.Add(fileInfo); cc.Load(upFile); cc.ExecuteQuery();
我可以使用这种方法上传once
,但现在我得到了ServerException :To add an item to a document library, use SPFileCollection.Add()
了cc.ExecuteQuery()
但是如果这个方法完全有效,我想要的是我应该更新与这个文件相关的列值。在第一种方法中,我得到了 item.ID,所以我可以从那里更新列值