-
Programmatically create Project documents in SharePoint 2013 using C#
about 9 years ago
about 9 years ago
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;
using Microsoft.SharePoint.Client;
context = new ClientContext(projectSiteUrl); //pass your project site url
context.Credentials = projectContext.Credentials;
2. Find list using list name
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
}
}
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)