Topic RSS
6:02 am
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/
Most Users Ever Online: 91
Currently Online:
16 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
jollekvin: 103
meredithscott: 30
NickJohnson: 19
spbsmile: 13
dshiftbyxavor: 13
laurenrodriguez: 12
Member Stats:
Guest Posters: 1113
Members: 16881
Moderators: 0
Admins: 1
Forum Stats:
Groups: 3
Forums: 10
Topics: 1141
Posts: 2551
Newest Members: Anoop Srivastav, Lakshmi, graicrorm, spootogaups, axiorneesee, Lenchik1971
Administrators: Learning SharePoint (212)

Log In
Members
Home
Add Reply
Add Topic
Quote
Offline
