如何向列表中添加数据值(开发篇补充REST)
2011-08-13 17:36
239 查看
SharePoint 2010中增加了对ADO.NET Service的支持。我们可以通过REST的方式来添加,查询或者更新数据。这篇文章,我将尝试使用REST的方式来查询,并且添加一条记录。
准备工作:开始使用代码之前,记得要添加对 http://servername/_vti_bin/listdata.svc 服务的引用。我是引用之后,将其命名为“ListDataSR”, 一下是详细代码。(我是在控制台程序中运行这段代码的)
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
本系列三篇文章对自己是一个积累,总结。希望对有需要的朋友能有所帮助。
准备工作:开始使用代码之前,记得要添加对 http://servername/_vti_bin/listdata.svc 服务的引用。我是引用之后,将其命名为“ListDataSR”, 一下是详细代码。(我是在控制台程序中运行这段代码的)
ListDataSR.SPFLearnDataContext ctx = new ListDataSR.SPFLearnDataContext( new Uri("http://servername/_vti_bin/listdata.svc")); public void AddNewItem() { ctx.Credentials = CredentialCache.DefaultCredentials; ListDataSR.JobsItem newJob = new JobsItem(); newJob.Title = "SharePoint QA"; newJob.JobDescription = "QA in SharePoint project"; newJob.CityValue = "Shanghai"; newJob.DueDate = DateTime.Now.AddDays(12); newJob.JobRequirementId = 2; newJob.ManagerId = 1; ctx.AddToJobs(newJob); ctx.SaveChanges(); } public void GetItems() { ctx.Credentials = CredentialCache.DefaultCredentials; var jobsInShanghai = from q in ctx.Jobs where q.CityValue =="Shanghai" select q; foreach (var item in jobsInShanghai) { Console.WriteLine( "Job Title: {0}; Due Date{1}; City:{2}", item.Title, item.DueDate, item.CityValue); } }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
本系列三篇文章对自己是一个积累,总结。希望对有需要的朋友能有所帮助。
相关文章推荐
- 学习:如何向列表中添加数据值(开发篇补充REST)(转)
- 学习:如何向列表中添加数据值(开发篇)(转)
- 如何向列表中添加数据值(开发篇)
- 如何向列表中添加数据值(管理员篇)
- C# 程序中如何向(DEV)ComboBoxEdit控件中添加下拉列表的值不使用数据绑定,就是使用代码添加
- 在InfoPath中如何添加数据连接到Sharepoint的列表或库
- 学习:如何向列表中添加数据值(管理员篇) (转)
- 如何自定义添加数据列表(数据单元格)
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- 数据窗口中分组后如何添加序号列?
- js如何向数组里面添加数据和遍历出来数组里面的内容
- jquery用ajax方式从后台获取json数据后如何将内容填充到下拉列表
- abap--如何根据动态公式计算数据(增补),谢谢网友补充
- SP2010开发和VS2010专家"食谱"--第六章节--Web Services和REST(2)--筛选列表数据
- Iphone开发(十一)从plist文件读取列表数据并添加索引
- 短信列表如何让同一个号码的短信只显示一条,刚刚加载短信列表会加载所有的数据列。求指教
- c++如何往map<string, set<string> > 添加数据
- python高效编程技巧1 (如何在列表,字典,集合中根据条件筛选数据)
- 如何把数据快速批量添加到Elasticsearch中
- List添加Item时, 如何去判断某个字段, 并且保证字段数据不重复性