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
    • 352
    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

    1. using Microsoft.SharePoint.Client;
    2. context = new ClientContext(projectSiteUrl); //pass your project site url
    3. context.Credentials = projectContext.Credentials;

    2. Find list using list name

    1. List spList = context.Web.Lists.GetByTitle("Documents");

    3.Add documents to lists

    1. if (spList != null)
    2.     {
    3.             try
    4.             {
    5.                 byte[] content = System.Text.Encoding.UTF8.GetBytes("FileLeafData");
    6.                 Microsoft.SharePoint.Client.File f = spList.RootFolder.Files.Add(new FileCreationInformation() { Url = "Project.docx", Overwrite = true, Content = content, });
    7.                 ListItem newListItem = f.ListItemAllFields;
    8.                 newListItem["FileLeafRef"] = "Project.docx";
    9.                 newListItem["Title"] = "Test";
    10.                 newListItem["MetaInfo"] = "Your Meta Info";
    11.                 newListItem.Update();
    12.                 context.ExecuteQuery();
    13.             }
    14.             catch (Exception ex)
    15.             {
    16.                 //log exception
    17.             }
    18.     }

    Hope this code will help you.

    Thanks

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: