Monday 21 February 2011

SharePoint Webservices - Retrieve Regional Settings for a site

How many times you run into culture related issues? I'll leave you to answer it to yourself. I tend to fall a lot especially while dealing with the SharePoint web services. When you retrieve any datetime field using web services you also need to know the format whether its US/UK or some other. Just by looking at the datetime string value you cannot predict the culture info. 

To give you an example here's the confusion:

11/11/2001. Is this American date format or English? well my answer is,  I don't know? But if you try to parse this value using default culture of your machine you wont get any format exception. But you'll get with 11/13/2001 if your code doesn't take datetime format into account and is running on UK machine. 

There's a limited set of information available with webs.asmx. When you try to retrieve using GetWeb method all you get is the language Id. Which is by default to 1033. 

What if your regional settings are set to UK and your code queries all list items using lists.asmx web service. The datetime is going to be in UK format especially for created and modified fields.  

So to fix this issue you would need to take the Regional Settings into account.

How to retrieve regional settings - using Sharepoint Web Services:

The only way I found to retrieve the regional settings of a web via web services is using a lists schema and by reading the element value i.e: RegionalSettings -> Locale ....

Let me know if you need the code examples. 

Hope this will help !

Majid


1 comment:

Addicted To Chaos said...

Thanks for sharing this Majid. In your tests, did you find the Locale in the response to be different in the cases where the Dates come back in the dd/mm/YYYY format for example? I was wondering if one could lean on the locale to determine what datetime format to expect in the GetListItems response.

Iconise ‘Add Picture’ control in PowerApps

Default look you get for ‘Add Picture’ control is not very appealing for end user and there is no OTB way of specifying icon for this con...