Click here to Skip to main content
15,884,298 members
Articles / Productivity Apps and Services / Sharepoint
Tip/Trick

SharePoint - Get the Current User's Regional Settings

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
16 Jan 2014CPOL2 min read 11K  
How to retrieve the current user's Regional Settings using SharePoint Designer


Introduction

This article describes how to retrieve the Regional Settings of the current user using SharePoint Designer.  This tip is useful for those users that do not have the appropriate permissions to add custom .Net code to SharePoint and are forced to use only SharePoint Designer.  This is specifically useful when a user modifies their regional settings to those different than the site default.

In my case, I discovered this tip when I needed the ability to format dates (based on the Locale ID).


Background 

This code was tested in SharePoint 2007 and SharePoint Designer 2007.  To change your personal regional settings do the following:

  1. In SharePoint web UI, click on your name (top right).
  2. Click My Settings. 
  3. Click My Regional Settings
  4. Modify as required.


Using the code 

The only place I could find where the regional settings were stored, was in the GetList method in the Lists.asmx web service (http://msdn.microsoft.com/en-us/library/lists.lists.getlist%28v=office.12%29.aspx).  Thus, we will use XML Web Service (SharePoint:SoapDataSource).

In this example, I will be accessing the Locale ID, so that I can determine how to format the dates returned. 

Steps

A. Create the XML Web Service (SoapDataSource).

  1. Open the page that you wish to edit in SharePoint Designer.
  2. In the Data Source Library window, under the XML Web Services, click on Connect to a web service... Image 1 
  3. In the Source tab, add the following to the Service description location:  <your site url>/_vti_bin/Lists.asmx?WSDL  (where <your site url> is the url to your site)
  4. Click Connect Now 
  5. Under Operation, Select GetListImage 2
  6. Select listName and click Modify.
  7. In Value, type in the name of any list in your site.  Please note, that the permission settings for this list should be available to everyone.  Click OK.Image 3 
  8. Click OK.

B. Access the XML Web Service through a DataFormWebPart.   The easiest way to demonstrate this would be to follow these steps: 

  1. On the same page as step A, click into the Code page and place the cursor to where you would like the data displayed. 
  2. Go to the Data Source Library.  Click on the newly created service from A.  Click Show Data. Image 4
  3. This will open the Data Source Details window. 
  4. Scroll down where RegionalSettings is displayed, select all fields under RegionalSettings.  Click Insert Selected Fields as...    
  5. Click on Single Item ViewImage 5 
  6. This will insert a DataFormWebPart onto the page.  When viewed from Design view, it will look something like this. Image 6 

C.  Modify the DataFormWebPart to accommodate your requirements.  As an example, I have modified the code so that the current date is saved to a hidden field.  The date stored here will represent the current date based on the appropriate regional settings of the user.

XML
<WebPartPages:DataFormWebPart runat="server" IsIncluded="True" FrameType="None" NoDefaultStyle="TRUE" ViewFlag="0" Title="List Title" __markuptype="vsattributemarkup" __WebPartId="{720D6BF3-073B-4E6F-AA4B-51802A4229F0}" id="g_720d6bf3_073b_4e6f_aa4b_51802a4229f0" pagesize="1" __AllowXSLTEditing="true" WebPart="true" Height="" Width=""><DataSources><SharePoint:SoapDataSource runat="server" id="SoapDataSource1" AuthType="None" WsdlPath="http://corp.net/sites/testSite/_vti_bin/Lists.asmx?WSDL" SelectUrl="http://corp.net/sites/testSite/_vti_bin/Lists.asmx" SelectAction="http://schemas.microsoft.com/sharepoint/soap/GetList" SelectPort="ListsSoap" SelectServiceName="Lists"><SelectCommand><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetList xmlns="http://schemas.microsoft.com/sharepoint/soap/"><listName>Test List</listName></GetList></soap:Body></soap:Envelope></SelectCommand></SharePoint:SoapDataSource></DataSources><ParameterBindings><ParameterBinding Name="dvt_apos" Location="Postback;Connection"/><ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/><ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/><ParameterBinding Name="dvt_firstrow" Location="Postback;Connection"/><ParameterBinding Name="dvt_nextpagedata" Location="Postback;Connection"/></ParameterBindings><datafields>ddw1:Language,Language;ddw1:Locale,Locale;ddw1:AdvanceHijri,AdvanceHijri;ddw1:CalendarType,CalendarType;ddw1:Time24,Time24;ddw1:TimeZone,TimeZone;ddw1:SortOrder,SortOrder;ddw1:Presence,Presence;</datafields><XSL><xsl:stylesheet xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ddw1="http://schemas.microsoft.com/sharepoint/soap/" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal"><xsl:output method="html" indent="no"/><xsl:decimal-format NaN=""/><xsl:param name="dvt_apos">'</xsl:param><xsl:param name="Today"/><xsl:template match="/"><xsl:call-template name="dvt_1"/></xsl:template><xsl:template name="dvt_1"><xsl:variable name="Rows" select="/soap:Envelope/soap:Body/ddw1:GetListResponse/ddw1:GetListResult/ddw1:List/ddw1:RegionalSettings"/><xsl:variable name="Locale" select="$Rows/ddw1:Locale"/><input type="hidden" id="formattedCurrentDateHDN" value="{ddwrt:FormatDate(string($Today), $Locale, 1)}"/></xsl:template></xsl:stylesheet></XSL></WebPartPages:DataFormWebPart>

History 





License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect GuiangStar Corp
Canada Canada
.in the MS development game for 14+ years.

Comments and Discussions

 
-- There are no messages in this forum --