小试SharePoint编程:用Web Service增加列表项
来源:互联网 发布:centos netsnmp 编辑:程序博客网 时间:2024/06/05 22:56
因工作需要对一个SharePoint的子站点进行更新,以前是手工做的。由于我不是这个站点的管理员,因此GOOLE之后,找到了这个方案,作了稍许修改。体会是:
1. 如果要更新的站点是一个子站点,即使已经添加了Web Service引用,还要在Uri属性中再次声明引用列表路径,否则会报错0x81020026;
2. 如果有日期字段,在XML文件中要设成yyyy-MM-ddTHH:mm:ssZ格式,否则会报日期格式不正确的错误;
3. XML文件中指定的字段名如有空格,要用_x0020_连接。如"User Name"要写成"User_x0020_Name"。
以下代码在VS2008中调试通过。
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace WebServiceTest1
{
class Program
{
static void Main(string[] args)
{
try
{
test();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine("END");
Console.Read();
}
private static void test()
{
LabPortal.Lists listService = new LabPortal.Lists();
listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
listService.Url = "http://site_name/subsite/_vti_bin/Lists.asmx"; //!!!
//ID是Method的唯一标识,如果有多个Method就都列在下面
//Cmd的类型有:New,Update,Delete。分别对应增加,删除,更新
"<Field Name='Date'>2008-09-12T09:00:00Z</Field>" + // use yyyy-MM-ddTHH:mm:ssZ format
"<Field Name='User_0x0020_name'>Ally McBeal</Field>" +
"</Method>";
XmlDocument xmlDoc = new XmlDocument();
XmlElement elBatch = xmlDoc.CreateElement("Batch");
//Batch元素下面的这些Attribue是可选的
elBatch.SetAttribute("OnError", "Continue"); //指定出错后是返回还是继续下一步
elBatch.SetAttribute("ListVersion", "1"); //指定列表的版本
//elBatch.SetAttribute("ViewName", "654446D3-8E70-4483-B2B6-F87329EAC2D9"); //指定所操作的列表视图GUID
elBatch.InnerXml = strBatch;
XmlNode ndReturn = listService.UpdateListItems("Test", elBatch); //在名为Test的列表中增加一条记录
Console.WriteLine(ndReturn.OuterXml); }
}
}
- 小试SharePoint编程:用Web Service增加列表项
- 通过WEB SERVICE读取SHAREPOINT列表数据
- SharePoint Web Service系列:进行列表的增删改
- SharePoint Web Service的身份验证
- SharePoint web service 介紹(1)
- SharePoint Web Service的身份验证
- SharePoint Web Service系列:编写自定义SharePoint Web Services之一
- SharePoint Web Service系列:编写自定义SharePoint Web Services之一
- 给sharepoint页面增加“Add Web Parts”
- SharePoint自带WebService(Authentication Web Service)
- SharePoint web service 介紹(2) - Lists
- Client Call SharePoint Web Service(SOAP)
- web service 小例子
- SharePoint 2010 列表视图导航Web部件
- SharePoint客户端开发:增加用户信息到用户信息列表
- Web service 的站点列表
- Web Service深度编程
- web-service编程规范
- 百度谴责阿里巴巴三鹿事件中造谣 称已取证
- XML 转义字符
- 仿 msn 闪屏震动
- problem 1622
- devfs、sysfs、udev介绍
- 小试SharePoint编程:用Web Service增加列表项
- SQL SERVER的数据类型
- 报表
- Configure DB2 remote connectivity with WebSphere DataStage Enterprise Edition
- 转朋友签名:命运负责洗牌,但玩牌的是我们自已!
- eclipse bug
- 美股“失火”殃及中国概念股
- test
- 子非鱼,安知鱼之乐---《庄子 秋水》