Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 944106 - Last Review: October 29, 2007 - Revision: 1.0
When you programmatically use the SPUser.RegionalSettings object on a server that is running Windows SharePoint Services 3.0, the value of the returned object is NULL
SYMPTOMS
When you programmatically use the SPUser.RegionalSettings object on a server that is running Microsoft Windows SharePoint Services 3.0, the value of the returned object is NULL.
CAUSE
This problem occurs if the user who is defined in the object is not the same user who is logged on to the server. By design, the SPUser.RegionalSettings object is for the current user. Therefore, the current user's regional settings are reported even when you are retrieving the settings of other users.
WORKAROUND
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To work around this problem, use the following code. This code uses a new SPSite object to create a separate user context.
String GetUserTimeZone(String strUserLogin)
{
String strResult = String.Empty;
SPSite site = new SPSite(<Sharepoint Site>);
SPWeb web = site.OpenWeb();
SPUser user = web.SiteUsers[strUserLogin];
site.Dispose();
using (SPSite siteUser = new SPSite(<Sharepoint Site>, user.UserToken))
{
SPWeb webUser = siteUser.OpenWeb();
SPUser userImp = webUser.SiteUsers[strUserLogin];
SPRegionalSettings rgnUser = userImp.RegionalSettings;
strResult = rgnUser == null ? "none" : rgnUser.TimeZone.Description;
}
return strResult;
}
Notes- This code correctly reports the user's regional settings, regardless of the browsing user's context.
- After you exit the "using" statement, you must be careful when you work with any objects that are retrieved while the objects are inside the "using" statement. The SPSite object and the underlying request that is used to collect the per-user regional settings will have been discarded. Performing the desired work inside the "using" statement is safest. However, other approaches are possible.
APPLIES TO
- Microsoft Windows SharePoint Services 3.0
| kbtshoot kbprogramming kbautomation kbprb kbcode kbpubtypekc kbexpertiseinter KB944106 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please