It's possible to add a description via content editor web part. But have too many document libraries, I just want to add it dynamically

enter image description here

It would be very great if you could help me with my problem.

  • 1
    Add you script in master page. Nov 11, 2016 at 5:44
  • Thank you, is it able to add the master page to document library level?
    – JishinK
    Nov 11, 2016 at 5:53
  • yes. you just need some configuration. you can find your Library Name using ctx.ListTitle. Configuration example: if (ctx.ListTitle == "A"){var des = "Test description"} Nov 11, 2016 at 6:05

2 Answers 2


the below endpoint can get you the description

http://site url/_api/web/lists/GetByTitle(‘Test')



Using managed client object model, you can add web part to the the page. You just need to have Url of the page.

using (ClientContext context =new ClientContext(""))
   Web web = context.Web;
   File file = web.GetFileByServerRelativeUrl("Page Url");//Page Url is the page where you want to add webpart.Doc lib view.keep all libraries in collection and traverse and get the view url of it
   LimitedWebPartManager wpm = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
   WebPartDefinition def = wpm.ImportWebPart(WebpartData);
   wpm.AddWebPart(def.WebPart, "Main", 0);

what is WebpartData data?

WebPartDefinition def = wpm.ImportWebPart(WebpartData);

WebpartData is the string variable which contains webpart data in xml.

Initially add your CEWP on one page and export this webpart and assign the content of .dwp file to WebpartData before above code.

for example.

   public static string WebpartContent = @"<WebPart                xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.microsoft.com/WebPart/v2"">
  <Title>Content Editor</Title>
  <Description>Allows authors to enter rich text content.</Description>
  <Height />
  <Width />
  <DetailLink />
  <HelpLink />
  <PartImageSmall />
  <MissingAssembly>Cannot import this Web Part.</MissingAssembly>
  <IsIncludedFilter />
  <Assembly>Microsoft.SharePoint, Version=, Culture= neutral, PublicKeyToken= 71e9bce111e9429c</Assembly>
  <ContentLink xmlns =""http://schemas.microsoft.com/WebPart/v2/ContentEditor"">/sites/testsite/SiteAssets/Calender_Weekend_Color.txt</ContentLink>  
 <PartStorage xmlns = ""http://schemas.microsoft.com/WebPart/v2/ContentEditor"" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.