惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
B
Blog
博客园 - Franky
I
InfoQ
A
About on SuperTechFans
博客园_首页
L
LangChain Blog
量子位
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
美团技术团队
V
V2EX
Apple Machine Learning Research
Apple Machine Learning Research
雷峰网
雷峰网
MongoDB | Blog
MongoDB | Blog
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
G
Google Developers Blog
Last Week in AI
Last Week in AI

博客园 - 范文轩

Sharepoint中的Feature Stapling功能 SharePoint 2010中的WebProvisioned Event Handler 如何向列表中添加数据值(开发篇) 如何向列表中添加数据值(管理员篇) 在SharePoint 2010中动态加载Visio Web Part 使用编程的方式来启动SharePoint的工作流 InfoPath 2010调用REST的一个小应用 SharePoint 2010 WSP包部署过程中究竟发生什么? 如何查看SharePoint 2010的CU版本 SharePoint 2010多语言包的安装 在SharePoint 2010中使用Linq时候,请注意特殊字符 自定义ASP.NET WebApplication中调用SharePoint2010的对象 在Infopath 2010中调用Web Service 谈谈SharePoint 2010的客户端对象模型的性能问题 给Document Set里面添加文件夹 给Chart Web Part 添加过滤功能 SharePoint 2010的Form认证的用户注册功能 SharePoint 调查列表的自定义错误页面 Reporting Services 2008 and SharePoint 2010
如何向列表中添加数据值(开发篇补充REST)
范文轩 · 2011-08-13 · via 博客园 - 范文轩

SharePoint 2010中增加了对ADO.NET Service的支持。我们可以通过REST的方式来添加,查询或者更新数据。这篇文章,我将尝试使用REST的方式来查询,并且添加一条记录。

准备工作:开始使用代码之前,记得要添加对 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);
    }                       
}

本系列三篇文章对自己是一个积累,总结。希望对有需要的朋友能有所帮助。