in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

pm4everyone's blog

SharePoint 2003 Querying with GMT DateTime

The issue is resolving ows_Created and ows_Modified timestamps for users in different timezones. Perhaps the documentation is wrong, but I noticed slightly different behaviour than what was described.

The problem at hand. We are integrating with the basic SharePoint Task List and are heavily dependent on proper date time-- especially across time zones.  What I needed was timezone information in a well formed ISO date time format with the UTC hours and minutes, or the date time set to GMT. What I got was neither a well-formed ISO date time or a GMT date time.

So off to Google to find out how to get a SharePoint servers timezone. To my dismay, it wasn't available via a web service call. Horrors! It was, of course, available via the SPModel, but that must run on the server and that isn't an option for our application.

So I went back to the above documentation that describes the Lists.GetListItems web service call and particularly the QueryOptions. From the documentation:

<QueryOptions>
<IncludeMandatoryColumns>FALSE
</IncludeMandatoryColumns>
<DateInUtc>TRUE</DateInUtc>
</QueryOptions>

DateInUtc

TRUE to return dates in Coordinated Universal Time (UTC) format.
FALSE to return dates in ISO format. This element is optional, and
its default values is TRUE.


And I had code doing this:

XmlDocument xmlDoc = new XmlDocument();

XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element,"Query","");
XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element,"ViewFields","");
           
string viewFields = "<FieldRef Name='" + s_vfID + "' />";
viewFields += "<FieldRef Name='" + s_vfTitle + "' />";
viewFields += "<FieldRef Name='" + s_vfCreatedOn + "' />";
ndViewFields.InnerXml = viewFields;

XmlNode node = null;
node = ls.GetListItems( m_nativeID, null, ndQuery, ndViewFields, null, null);

One would think that would use the default QueryOption behaviour. But then one would be wrong. I found out through much trial and tribulation (once again) that you can't always trust the documentation, or at least your interpretation of it.

If you really want that CreatedOn field to be GMT, you have to specify the QueryOption fragment like this:

XmlDocument xmlDoc = new XmlDocument();

XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element,"Query","");
XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element,"ViewFields","");
XmlNode ndQueryOptions =      xmlDoc.CreateNode(XmlNodeType.Element,"QueryOptions","");
           
string viewFields = "<FieldRef Name='" + s_vfID + "' />";
viewFields += "<FieldRef Name='" + s_vfTitle + "' />";
viewFields += "<FieldRef Name='" + s_vfCreatedOn + "' />";
ndViewFields.InnerXml = viewFields;

ndQueryOptions.InnerXml = "<DateInUtc>TRUE</DateInUtc>";

XmlNode node = null;
node = ls.GetListItems( m_nativeID, null, ndQuery, ndViewFields, null, ndQueryOptions);


The next question I'm working on: why do RichText fields in SharePoint return html when retrieved via web services? Go head, use that rich text control in a sharepoint task description, and then look at it in MS Word. Hmmm....

Comments

No Comments

Leave a Comment

(required )  
(optional )
(required )  
Add

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts