in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Mirjam's blog

Blogging about SharePoint related stuff

Impersonation in SharePoint 2007

In SharePoint 2003 there was no easy way to use impersonation. In SharePoint 2007 there is a nice and easy build in way to use impersonation:

SPSite site = new SPSite("SiteCollection_Url");
SPWeb web = site.OpenWeb();
SPUser user = web.AllUsers["User_Name"];

SPUserToken token = user.UserToken;
SPSite impersonatedSiteCollection = new SPSite("SiteCollection_Url", token);

You can also check whether an SPSite object is using impersonation:

SPSite siteCollection = SPControl.GetContextSite(HttpContext.Current);
bool impersonating = siteCollection.Impersonating;

Comments

 

Norman said:

Thanks, thanks a lot.

I spent 1 week to find this solution.

I love you......

November 6, 2007 9:54 AM

Leave a Comment

(required )  
(optional )
(required )  
Add

About Mirjam

Mirjam van Olst works as a lead SharePoint developer at Macaw in the Netherlands. She started working for Macaw in April 2004. Before that she had her own company (Van Olst Websolutions) with which she build web applications. Mirjam has specialized in SharePoint development since June 2004. She started working with the 2007 Office system in may 2006. She has implemented several world-wide intranet environments based on SharePoint. She also gives presentations about MOSS 2007 on a regular basis and occasionally writes articles about MOSS related subjects.

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts