using (ClientContext clientContext = new ClientContext("URLSHAREPOINT"))
{
SecureString passWord = new SecureString();
foreach (char c in "PASSWORD".ToCharArray()) passWord.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials("USERNAME.onmicrosoft.com", passWord);
Web web = clientContext.Web;
FileCreationInformation newFile = new FileCreationInformation();
newFile.Content = System.IO.File.ReadAllBytes(@"FILELOCATION");
newFile.Url = "file uploaded via client OM.txt";
List docs = web.Lists.GetByTitle("LIBRARYNAME");
Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);
clientContext.ExecuteQuery();
}
我使用上面的代码将文件上传到我的Sharepoint 365帐户! 但我也需要添加一些元数据
有人可以帮助我使用我当前的代码添加元数据吗?
答案 0 :(得分:1)
clientContext.Load(docList);
clientContext.Load(docList.Fields.GetByTitle("METADATANAME"));
clientContext.Load(docList.Fields.GetByTitle("METADATANAME"));
clientContext.ExecuteQuery();
var Nome = docList.Fields.GetByTitle("METADATANAME").InternalName;
var Posicao = docList.Fields.GetByTitle("METADATANAME").InternalName;
uploadFile.ListItemAllFields[Nome] = "VALUE";
uploadFile.ListItemAllFields[Posicao] = "VALUE";
uploadFile.ListItemAllFields.Update();
clientContext.Load(uploadFile);
clientContext.ExecuteQuery();
这很有效!希望用这个来帮助一些人=)