Again, I want to share some of my encapsulated methods. So, I’ve been through so many projects, developing this and that, with the same pattern. It very helpful when you choose to use encapsulation and get it for later use.
This method is about get SharePoint user profile. You can use this code whether you are using SharePoint 2007 or SharePoint 2010. Enjoy…
Code Snippet
- public static UserProfile GetUserProfile(string LoginName)
- {
- return GetUserProfile(SPContext.Current.Site, LoginName);
- }
- public static UserProfile GetUserProfile(SPSite Site, string LoginName)
- {
- return GetUserProfile(Site, LoginName, true);
- }
- public static UserProfile GetUserProfile(SPSite Site, string LoginName, bool RevertSystemAccount)
- {
- //check if SharePoint System Account
- if (IsSharePointSystem(LoginName) && RevertSystemAccount)
- LoginName = Site.WebApplication.ApplicationPool.Username;
- SPUser Usr = Site.RootWeb.EnsureUser(LoginName);
- ServerContext SCtx = ServerContext.GetContext(Site);
- UserProfileManager UPM = new UserProfileManager(SCtx);
- if (UPM.UserExists(Usr.LoginName)) { return UPM.GetUserProfile(Usr.LoginName); }
- else return null;
- }
what an idea sirjee ??
BalasHapus:D wat is "sirjee"?
Hapussirjee means boss...!
Hapusthanks for above snnipt