Link to home
Start Free TrialLog in
Avatar of Thomas Pettinicchi
Thomas Pettinicchi

asked on

Add document set to library SharePoint Online

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 :

    ClientContext clientContext = GetonlineContext();    
                Web spWeb = clientContext.Web;  
                var formLib = spWeb.Lists.GetByTitle("Event");  
                ContentTypeCollection listContentTypes = formLib.ContentTypes;  
                ContentTypeId dsCtId = new ContentTypeId();  
                clientContext.Load(listContentTypes, types => types.Include(type => type.Id, type => type.Name, type => type.Parent));  
                var result = clientContext.LoadQuery(listContentTypes.Where(c => c.Name == "Events"));  
                clientContext.ExecuteQuery();  
                ContentType docsetCT = result.First();  
                ContentTypeId ctid = docsetCT.Id;  
                DocumentSet.Create(clientContext, formLib.RootFolder, value.name, ctid);  
                clientContext.ExecuteQuery();

 

    private class Configuration  
            {  
                public static string ServiceSiteUrl = "https://****.sharepoint.com";  
                public static string ServiceUserName = "*****";  
                public static string ServicePassword = "******";  
            }  
            static ClientContext GetonlineContext()  
            {  
                var securePassword = new SecureString();  
                foreach (char c in Configuration.ServicePassword)  
                {  
                    securePassword.AppendChar(c);  
                }  
                var onlineCredentials = new SharePointOnlineCredentials(Configuration.ServiceUserName, securePassword);  
                var context = new ClientContext(Configuration.ServiceSiteUrl);  
                context.Credentials = onlineCredentials;  
                return context;  
            }

 
But when i execute, there is no document add to the library.
 
Can you please help me ? I'm lost ...

My final goal is to host on azure a web service where people can upload document set with simple HTTP POST request, but i dont know if it's possible ...
 
Thanks a lot !
Avatar of Colleen Kayter
Colleen Kayter
Flag of United States of America image

I think you have a syntax error in line 7: c.Name == "Events"
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.