Ok, here is what I did to solve this problem:
- make a list request for 1 element, the retrieval time for the site locale
- make a request for this item, get the time in UTC
- calculate the difference between the two results.
the code:
private TimeSpan getSiteTZOffset(List list, WSLists.Lists client )
{
XmlDocument xmlDoc = new XmlDocument();
XmlNode emptyQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
XmlNode queryWithID = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
XmlNode ndOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");
ndOptions.InnerXml = "<DateInUtc>True</DateInUtc>";
XmlNamespaceManager xnm = new XmlNamespaceManager(xmlDoc.NameTable);
xnm.AddNamespace("z", "#RowsetSchema");
MapAttribute modifiedDateAttr = attributes.Single(x => x.Value.DateTimeModifiedField).Value;
MapAttribute idAttr = attributes.Single(x => x.Value.KeyReference).Value;
XmlNode resLocalTime = client.GetListItems(list.ListID, list.ViewID, emptyQuery, null, "1", null, null);
XmlNodeList itemsLocalTime = resLocalTime.SelectNodes("//z:row", xnm);
queryWithID.InnerXml = string.Format("<Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>{0}</Value></Eq></Where>",
itemsLocalTime[0].Attributes[idAttr.Name].Value);
XmlNode resUtc = client.GetListItems(list.ListID, list.ViewID, queryWithID, null, "1", ndOptions, null);
XmlNodeList itemsUtc = resUtc.SelectNodes("//z:row", xnm);
DateTime localTime = DateTime.Parse(itemsLocalTime[0].Attributes[modifiedDateAttr.Name].Value);
DateTime utcTime = getUtcTime(itemsUtc[0].Attributes[modifiedDateAttr.Name].Value);
TimeSpan offset = localTime - utcTime;
return offset;
}
source
share