我正在创建一个 Windows 窗体,它从共享点客户端对象模型加载列表项。
我遇到了日期字段的问题,它给出了+1天或-1天,即如果我输入的日期为2014年5月5日,它会给出2014年5月6日或有时为2014年5月4日。
_query.ViewXml = "<View><Query><Where>" +
"<And><Geq><FieldRef Name='Effort_x0020_Date'/><Value IncludeTimeValue='FALSE' Type='DateTime'>" + conStartDate + "</Value></Geq>" +
"<And><Leq><FieldRef Name='Effort_x0020_Date'/><Value IncludeTimeValue='FALSE' Type='DateTime'>" + conEndDate + "</Value></Leq>" +
"<Eq><FieldRef Name='Author' LookupId=’TRUE’/><Value Type=’Text’>" + UserID + "</Value></Eq></And></And></Where>" +
"<GroupBy Collapse='TRUE'><FieldRef Name='WBS_x0020_Code'/></GroupBy></Query><RowLimit>25</RowLimit></View>";
SP.ListItemCollection _listitems = list.GetItems(_query);
clientcontext.ExecuteQuery();
执行此操作后,如果我使用下面的代码,它可以正常工作,但需要很多时间。
foreach(ListItem item in _listitems) {
DateTime start = ((DateTime) item["Effort_x0020_Date"]);
ClientResult < string > result = Utility.FormatDateTime(clientcontext, clientcontext.Web, start, DateTimeFormat.DateTime);
clientcontext.ExecuteQuery();
DateTime rightStart = Convert.ToDateTime(result.Value, new CultureInfo((int) web.Language));
//item["Effort_x0020_Date"] = rightStart;
}
不知何故,我想要一种可以更快地完成此操作的替代方法,以便避免每次连接到共享点。
最佳答案
我通过放置解决了这个问题
_query.DatesInUtc=false.
成功了!!
关于com - 从客户端对象中的 Sharepoint 列表检索时转换日期字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23471188/