Forum Discussion

Ruyam Lasre's avatar
Ruyam Lasre
Copper Contributor
Jan 04, 2018

How to read site page contents?

I want to read the contents of the sitepages(.aspx) present in the site. How can I achieve it? Here is my pseudo code

 

 _context.Load(pageItem, tmp => tmp.DisplayName, tmp => tmp.ContentType,
               tmp => tmp.File, tmp => tmp.File.Versions,
               tmp => tmp.FieldValuesAsText,
               tmp => tmp.Folder.ServerRelativeUrl,
               tmp => tmp.FieldValuesAsHtml);
_context.ExecuteQuery();

foreach (var fd in pageItem.FieldValuesAsHtml.FieldValues)
{
    Console.WriteLine(fd.Key+"   "+ fd.Value);//not having any field values

}           

LimitedWebPartManager lwpmShared =  pageItem.File.GetLimitedWebPartManager(PersonalizationScope.Shared);
LimitedWebPartManager lwpmUser =  pageItem.File.GetLimitedWebPartManager(PersonalizationScope.User);

WebPartDefinitionCollection webPartDefinitionCollectionShared = lwpmShared.WebParts;
WebPartDefinitionCollection webPartDefinitionCollectionUser = lwpmUser.WebParts;

 _context.Load(webPartDefinitionCollectionShared, w => w.Include(wp => wp.WebPart, wp => wp.Id));
 _context.Load(webPartDefinitionCollectionUser, w => w.Include(wp => wp.WebPart, wp => wp.Id));
 _context.Load( pageItem.File);
 _context.Load( _context.Web, p => p.Url);
 _context.ExecuteQuery();


foreach (var wpse in webPartDefinitionCollectionShared)//Collection returns zero items
{}

foreach (var wps in webPartDefinitionCollectionUser)//Collection returns zero items
{ }
No RepliesBe the first to reply

Resources