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
It would be very great if you could help me with my problem.
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityIt's possible to add a description via content editor web part. But have too many document libraries, I just want to add it dynamically
It would be very great if you could help me with my problem.
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
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>";
ctx.ListTitle
. Configuration example:if (ctx.ListTitle == "A"){var des = "Test description"}
– Atish Dipongkor - MVP Nov 11 '16 at 6:05