Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Programmatically create Project documents in SharePoint 2013 using C#

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 299
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: