2

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. – Atish Dipongkor - MVP Nov 11 '16 at 5:44
  • Thank you, is it able to add the master page to document library level? – JishinK Nov 11 '16 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"} – Atish Dipongkor - MVP Nov 11 '16 at 6:05
1

the below endpoint can get you the description

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

https://msdn.microsoft.com/en-us/library/office/dn292552.aspx

| improve this answer | |
1

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
   context.Load(file);
   context.ExecuteQuery();
   LimitedWebPartManager wpm = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
   WebPartDefinition def = wpm.ImportWebPart(WebpartData);
   wpm.AddWebPart(def.WebPart, "Main", 0);
   context.ExecuteQuery();
}

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>
  <FrameType>Default</FrameType>
  <Description>Allows authors to enter rich text content.</Description>
  <IsIncluded>true</IsIncluded>
  <ZoneID>Main</ZoneID>
  <PartOrder>0</PartOrder>
  <FrameState>Normal</FrameState>
  <Height />
  <Width />
  <AllowRemove>true</AllowRemove>
  <AllowZoneChange>true</AllowZoneChange>
  <AllowMinimize>true</AllowMinimize>
  <AllowConnect>true</AllowConnect>
  <AllowEdit>true</AllowEdit>
  <AllowHide>true</AllowHide>
  <IsVisible>true</IsVisible>
  <DetailLink />
  <HelpLink />
  <HelpMode>Modeless</HelpMode>
  <Dir>Default</Dir>
  <PartImageSmall />
  <MissingAssembly>Cannot import this Web Part.</MissingAssembly>
  <PartImageLarge>/_layouts/15/images/mscontl.gif</PartImageLarge>
  <IsIncludedFilter />
  <Assembly>Microsoft.SharePoint, Version= 16.0.0.0, Culture= neutral, PublicKeyToken= 71e9bce111e9429c</Assembly>
  <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
  <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"" />
 </WebPart>";
| improve this answer | |

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.