动态更新今天的日期 [英] dynamic update of todays date

查看:65
本文介绍了动态更新今天的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i 拥有SharePoint列表 使用列 标题和今天日期


当我在01-04-2013添加项目时显示



标题     TodayDate


x         ;    01-04-2013 


之后,


如果 我在05-01-2013上添加项目显示


标题      TodayDate


X       &NBSP ;    01-04-2013 


y             01-05-2013


但我需要输出为


标题     TodayDate


X       &NBSP ;    01-05-2013 


y             01-05-2013


怎么能 自动更新  TodayDate  列仅显示所有项目中的当前日期,而不运行任何工作流程


¥b $ b








 

解决方案


你可以与CSOM自动这样更新TodayDate列当前日期:


<预类= "prettyprint"> ClientContext clientContext =新ClientContext(QUOT; HTTP:// SP /位点的/ dev /") ;
Microsoft.SharePoint.Client.List spList = clientContext.Web.Lists.GetByTitle(" myList");
clientContext.Load(spList);
clientContext.ExecuteQuery();

如果(spList = NULL&安培;!&安培; spList.ItemCount&0)
{
Microsoft.SharePoint.Client.CamlQuery camlQuery =新CamlQuery();
camlQuery.ViewXml ="" ;;
ListItemCollection listItems = spList.GetItems(camlQuery);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
foreach(listItems中的Microsoft.SharePoint.Client.ListItem项)
{
item [" TodayDate"] = DateTime.Now;
item.Update();
clientContext.ExecuteQuery();
}
}

谢谢


最好的问候


i  have SharePoint list  with columns title and Today date

when i add item on 01-04-2013 it shows

Title     TodayDate

x            01-04-2013 

After that,

If  i add item on 05-01-2013 it shows

Title     TodayDate

x            01-04-2013 

y            01-05-2013

But I need output as

Title     TodayDate

x            01-05-2013 

y            01-05-2013

How can  update automatically TodayDate column shows current date only in all items without running any workflow




 

解决方案

Hi,

You could update the TodayDate column to current Date with CSOM automatically like this:

            ClientContext clientContext = new ClientContext("http://sp/sites/dev/");
            Microsoft.SharePoint.Client.List spList = clientContext.Web.Lists.GetByTitle("myList");
            clientContext.Load(spList);
            clientContext.ExecuteQuery();

            if (spList != null && spList.ItemCount > 0)
            {
                Microsoft.SharePoint.Client.CamlQuery camlQuery = new CamlQuery();
                camlQuery.ViewXml = "";
                ListItemCollection listItems = spList.GetItems(camlQuery);
                clientContext.Load(listItems);
                clientContext.ExecuteQuery();
                foreach (Microsoft.SharePoint.Client.ListItem item in listItems)
                {
                    item["TodayDate"] = DateTime.Now;
                    item.Update();
                    clientContext.ExecuteQuery();
                }
            }

Thanks

Best Regards


这篇关于动态更新今天的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆