C# 如何使用c在SharePoint中将字符串初始化为日期时间字段类型#
我正在SharePoint中使用visual studio创建一个应用程序,该应用程序计算两个日期之间的月数。我在初始化一个值时遇到问题。代码如下所示C# 如何使用c在SharePoint中将字符串初始化为日期时间字段类型#,c#,visual-studio-2010,sharepoint,sharepoint-2010,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["N
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
任何人都可以帮我吗?日期时间不能是字符串,但可以使用.ToString()将其转换为字符串;为了将字符串分配给datetime变量,需要对其进行解析或转换。可以使用Convert类将字符串更改为datetime格式 例如:
public string aDate = "01/01/2015";
public DateTime sDate;
sDate = Convert.ToDateTime(aDate); //sDate now has a value of 01/01/2015
我假设您有一个名为
Sdate
的列的SpListItem itm
。请看下面的代码,这对我来说很好
DateTime _Sdate = Convert.ToDateTime(itm["Sdate"].toString());
newDef = jobDef.Items.Add();
newDef["Sdate"] = _Sdate;
newDef["Ndate"] = "07/06/2015";
newDef["Cdate"] = calcDay();
newDef.Update();
是的,你是对的,但这在我的情况下不起作用。不管怎样,我需要调用Sdate字段thanks@NderonHyseni如果它不起作用,这是一个比你发布的问题更广泛的问题,我建议发布完整的工作流程。嘿,塔兰,非常感谢,它工作得很好。非常感谢上帝保佑你,你为我节省了很多时间@恩德隆希尼..这就是我加入StackOverflow的原因。谢谢你的欣赏。:)但是Taran您知道在这个问题上该怎么做吗:您需要执行newTask.getItem()或使用查询来获取所需的项。你不能更新你没有的东西!正确的?