c# - 如何使用 C# 在 SharePoint 中将字符串初始化为日期时间字段类型

标签 c# visual-studio-2010 sharepoint sharepoint-2010

我正在 SharePoint 中使用 visual studio 创建一个应用程序,计算两个日期之间的月数。我在初始化一个值时遇到问题。代码属于如下

DateTime _Sdate = ["Sdate"] //this one here does not work 
newDef = jobDef.Items.Add();
newDef["Sdate"] = "01/01/2015"; // i want to initialize this field to _Sdate
newDef["Ndate"] = "07/06/2015";
newDef["Cdate"] = calcDay() // I have this function in my project

谁能帮帮我?

最佳答案

我假设您有一个 SpListItem itm,其中的列名为 Sdate。请查看下面的代码,它对我来说效果很好。

DateTime _Sdate = Convert.ToDateTime(itm["Sdate"].toString());
newDef = jobDef.Items.Add();
newDef["Sdate"] = _Sdate;
newDef["Ndate"] = "07/06/2015";
newDef["Cdate"] = calcDay(); 
newDef.Update();

关于c# - 如何使用 C# 在 SharePoint 中将字符串初始化为日期时间字段类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31247405/

相关文章:

visual-studio-2010 - 我可以在构建解决方案时强制 Visual Studio (2010) 执行 "Save All"吗?

.net - 网页中的图表

c# - WCF 客户端错误 : "The address of the security token issuer is not specified"

c# - 我应该为意外的 null 值抛出什么异常?

c# - 嵌套对象上的Elasticsearch过滤器范围

html - 是否有使用 Razor 生成静态 HTML 页面的示例?

python - PTVS + Django : why can i not import python libraries

c# - C# 通用 Windows 应用程序如何接受命令行参数 (args)

c# - WCF运行时异常 "Could not find default endpoint element that references..."

sharepoint - 是否可以在 SharePoint 文档库中创建 'link to a folder'?