Each project has its own documents in SharePoint.
For creating the Project documents, first of all we have to create context by passing the projectSiteUrl.
1. Create context of projectSiteUrl
using Microsoft.SharePoint.Client;
context = new ClientContext(projectSiteUrl); //pass your project site url
context.Credentials = projectContext.Credentials;
2. Find list using list name
List spList = context.Web.Lists.GetByTitle("Documents");
3.Add documents to lists
if (spList != null)
{
try
{
byte[] content = System.Text.Encoding.UTF8.GetBytes("FileLeafData");
Microsoft.SharePoint.Client.File f = spList.RootFolder.Files.Add(new FileCreationInformation() { Url = "Project.docx", Overwrite = true, Content = content, });
ListItem newListItem = f.ListItemAllFields;
newListItem["FileLeafRef"] = "Project.docx";
newListItem["Title"] = "Test";
newListItem["MetaInfo"] = "Your Meta Info";
newListItem.Update();
context.ExecuteQuery();
}
catch (Exception ex)
{
//log exception
}
}
Hope this code will help you.
Thanks
0 Comment(s)