Microsoft KB Archive/944106

= 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 =

Article ID: 944106

Article Last Modified on 10/29/2007

-

APPLIES TO


 * Microsoft Windows SharePoint Services 3.0

-



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(); SPWeb web = site.OpenWeb; SPUser user = web.SiteUsers[strUserLogin]; site.Dispose;

using (SPSite siteUser = new SPSite(, user.UserToken)) {       SPWeb webUser = siteUser.OpenWeb; SPUser userImp = webUser.SiteUsers[strUserLogin]; SPRegionalSettings rgnUser = userImp.RegionalSettings; strResult = rgnUser == null ? &quot;none&quot; : 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 &quot;using&quot; statement, you must be careful when you work with any objects that are retrieved while the objects are inside the &quot;using&quot; 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 &quot;using&quot; statement is safest. However, other approaches are possible.

Additional query words: wss3 wss30 wss3.0

Keywords: kbtshoot kbprogramming kbautomation kbprb kbcode kbpubtypekc kbexpertiseinter KB944106

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.