【发布时间】:2018-02-06 17:52:35
【问题描述】:
我正在处理需要将日期从一个列表迁移到另一个列表的项目。我的源列表的日期时间格式为 MM/DD/YY,我的目标列表字段的日期时间格式为 DD/MM/YY。当我在目的地解析值时,它的转换不正确。
从列表字段中读取值的代码。
ClientContext ctx = new ClientContext(targetURL);
ctx.Credentials = new SharePointOnlineCredentials(userName, passWord);
ctx.Load(ctx.Web);
SP.ListCollection listCol = web.Lists;
ctx.Load(listCol);
SP.List list = listCollection.GetByTitle("ListTitle");
SP.CamlQuery camlQuery = new SP.CamlQuery();
camlQuery.ViewXml = "";
SP.ListItemCollection listItemCollection = list.GetItems(camlQuery);
ctx.Load(listItemCollection);
//Execute Query
ctx.ExecuteQuery();
foreach (ListItem _item in listItemCollection)
{
ctx.Load(_item,tmp => tmp.FieldValuesAsHtml);
ctx.ExecuteQuery();
foreach (var fieldValue in _item.FieldValuesAsHtml.FieldValues)
{
string _value = fieldValue.Value; //for datetime field returning value as string
}
}
在目标列表中将 _Value 转换为日期时间
destItem["Date"]= Convert.ToDateTime(_value);
//date is getting changed as DateTime format is diffrent.
如何获取源列表的 DateTime 格式?
【问题讨论】:
标签: sharepoint sharepoint-online csom