zoukankan      html  css  js  c++  java
  • SharePoint Web Service系列:进行列表的增删改

    异构应用访问SharePoint的文档库或列表时,使用WebService的方式再恰当不过了。有朋友问我如何在dotNet Framework 3.0下的应用程序中控制SharePoint 2003中的列表项。想一想类似的场景应该比较常见,所以写了下面的demo。以下的代码在VS2005中测试通过。

    using System;
    using System.Xml;
    using System.Collections.Generic;
    using System.Text;

    namespace ConsoleDemo
    {
        
    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 ConsoleDemo.LabPortal.Lists();
                listService.Credentials 
    = System.Net.CredentialCache.DefaultCredentials;

                
    string strBatch = "<Method ID='1' Cmd='New'>"+  //
                                                                
    //ID是Method的唯一标识,如果有多个Method就都列在下面
                                                                
    //Cmd的类型有:New,Update,Delete。分别对应增加,删除,更新
                    "<Field Name='ID'>New</Field>"+             //
                                                                
    //ID在增加操作时只是个唯一标记,可以随便指定,并不对应到实际
                                                                
    //listitem的ID。但在删除和更新时就必须是实际的ID了,因为要靠这个来唯一指定一条记录
                    "<Field Name='Title'>Smf</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("Contracts", elBatch);  //在名为Contracts的联系人列表中增加一条记录
                
                Console.WriteLine(ndReturn.OuterXml);
            }
        }
    }
  • 相关阅读:
    写代码实现两个 goroutine,其中一个产生随机数并写入到 go channel 中,另外一 个从 channel 中读取数字并打印到标准输出。最终输出五个随机数。
    05| RWMutex:读写锁的实现原理及避坑指南
    go 面试题
    go 局部变量在哪
    12 _ atomic:要保证原子操作,一定要使用这几种方法
    11 _ Context:信息穿透上下文
    什么是线程
    go面试题
    redis连接池 go
    docker 指定版本rpm包安装
  • 原文地址:https://www.cnblogs.com/Sunmoonfire/p/526591.html
Copyright © 2011-2022 走看看