2014-05-14 4 views
1
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 위 코드로 파일 업로드! 하지만 일부 메타 데이터도 추가해야합니다메타 데이터 필드를 사용하여 파일 업로드

누군가가 도와 줄 수 있습니까? 내 corrent 코드를 사용하여 메타 데이터를 추가 하시겠습니까?

답변

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(); 

희망이있는 사람이 = =)

관련 문제