Sharepoint 上载带有元数据字段的文件
我正在用上面的代码将文件上载到我的Sharepoint 365帐户! 但我也需要添加一些元数据 有人能帮我用相应的代码添加元数据吗Sharepoint 上载带有元数据字段的文件,sharepoint,file-upload,metadata,sharepoint-2013,Sharepoint,File Upload,Metadata,Sharepoint 2013,我正在用上面的代码将文件上载到我的Sharepoint 365帐户! 但我也需要添加一些元数据 有人能帮我用相应的代码添加元数据吗 using (ClientContext clientContext = new ClientContext("URLSHAREPOINT")) { SecureString passWord = new SecureString(); foreach (char c in "
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();
}
这是工作!希望能在这方面帮助一些人=)
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();