Please consider registering
guest

Log In Members

Lost password?
Advanced Search:

— Forum Scope —



— Match —



— Forum Options —




Wildcard usage:
*  matches any number of characters    %  matches exactly one character

Minimum search word length is 4 characters - maximum search word length is 84 characters

Topic RSS
Console application - accessing all webparts of a publishing page
August 23, 2012
6:02 am
abigail brown
Guest

Introduction:

Recently, we have been working on a sharepoint console app that finds invalid metadata terms assigned to web part properties. To get started we were trying to get all web parts on a publishing page.

Problem​:

There were several CQWP on page which were showing as error webparts when you get them using LimitedWebPartManager.

Solution:

Since CQWP and other publishing site web parts uses HttpContext.Current, we have to create a fake object in order to get it working properly. Here is the code that was included before GetLimitedWebPart call:

   1:  if (HttpContext.Current == null)
   2:  {
   3:  HttpRequest request = new HttpRequest("", web.Url, "");
   4:  HttpContext.Current = new HttpContext(request,
   5:  new HttpResponse(new StringWriter()));
   6:  HttpContext.Current.Items["HttpHandlerSPWeb"] = web;
   7:  WindowsPrincipal wP = new WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent());
   8:  HttpContext.Current.User = Thread.CurrentPrincipal = wP;
   9:  }​
 
To get More information from our sharepoint Development Visit - http://www.binaryrepublik.com/
September 3, 2012
10:10 am
Member
Forum Posts: 30
Member Since:
September 3, 2012
Offline

Looking forward to reading more. Great post.Thanks Again. Really Great.

Forum Timezone: UTC 0

Most Users Ever Online: 91

Currently Online:
16 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Member Stats:

Guest Posters: 1113

Members: 16881

Moderators: 0

Admins: 1

Forum Stats:

Groups: 3

Forums: 10

Topics: 1141

Posts: 2551

Administrators: Learning SharePoint (212)