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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
D
Docker
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
Vercel News
Vercel News
F
Fortinet All Blogs
B
Blog
Recent Announcements
Recent Announcements
A
About on SuperTechFans
GbyAI
GbyAI
T
The Blog of Author Tim Ferriss
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
MongoDB | Blog
MongoDB | Blog
Stack Overflow Blog
Stack Overflow Blog
B
Blog RSS Feed
C
Check Point Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
Visual Studio Blog
月光博客
月光博客

博客园 - 范文轩

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);
    }                       
}

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