Add document set to library SharePoint Online

Mar 27 2017 8:59 AM
Hello,
 
I'm trying to create a document set in a document library SharePoint online.
 
I have a special document set for this : Events
 
 
 
 I need to create this event in à webservice Azure, and i try with this code :
 
  1. ClientContext clientContext = GetonlineContext();    
  2.             Web spWeb = clientContext.Web;  
  3.             var formLib = spWeb.Lists.GetByTitle("Event");  
  4.             ContentTypeCollection listContentTypes = formLib.ContentTypes;  
  5.             ContentTypeId dsCtId = new ContentTypeId();  
  6.             clientContext.Load(listContentTypes, types => types.Include(type => type.Id, type => type.Name, type => type.Parent));  
  7.             var result = clientContext.LoadQuery(listContentTypes.Where(c => c.Name == "Events"));  
  8.             clientContext.ExecuteQuery();  
  9.             ContentType docsetCT = result.First();  
  10.             ContentTypeId ctid = docsetCT.Id;   
  11.             DocumentSet.Create(clientContext, formLib.RootFolder, value.name, ctid);  
  12.             clientContext.ExecuteQuery(); 
 
  1. private class Configuration  
  2.         {  
  3.             public static string ServiceSiteUrl = "https://****.sharepoint.com";  
  4.             public static string ServiceUserName = "*****";  
  5.             public static string ServicePassword = "******";  
  6.         }  
  7.         static ClientContext GetonlineContext()  
  8.         {  
  9.             var securePassword = new SecureString();  
  10.             foreach (char c in Configuration.ServicePassword)  
  11.             {  
  12.                 securePassword.AppendChar(c);  
  13.             }  
  14.             var onlineCredentials = new SharePointOnlineCredentials(Configuration.ServiceUserName, securePassword);  
  15.             var context = new ClientContext(Configuration.ServiceSiteUrl);  
  16.             context.Credentials = onlineCredentials;  
  17.             return context;  
  18.         } 
 
But when i execute, there is no document add to the library.
 
Can you please help me ? I'm lost ...
 
Thanks a lot !
 

Answers (2)