複数のファイルをドキュメント ライブラリにアップロードし、その列の値も更新しようとしています。List(Doc Lib) は既に存在しますが、ファイルのアップロードに行き詰まっています
私はこれらの方法を試しました
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 を取得するので、そこから列の値を更新できます