• 深入浅出SharePoint——批处理高效导入数据


    If you are using the Lists.asmx web service the hyper link column must be in the format of "link, description". For example http:\\www.whatever.com, nice site. The user column must be in the format of ID;#Domain\UserName. So you will need to construct this. You can get this information calling the UserGroup.asmx webservice's UserInfo method. Below is example code of populating a list with a new item using a user and hyperlink column:

      listservice.Lists listProxy = new listservice.Lists();

                string xml = "<Batch OnError='Continue'><Method ID='1' Cmd='New'><Field Name='ID'/><Field Name='usercol'>1;#BASESMCDEV2\\steve.curran</Field><Field Name='hyperlinkcol'>http://www.certdev.com, cool site</Field></Method></Batch>";

                XmlDocument doc = new XmlDocument();

                doc.LoadXml(xml);

                XmlNode batchNode = doc.SelectSingleNode("//Batch");

                listProxy.Url = "http://basesmcdev2/sites/tester1/_vti_bin/lists.asmx";

                listProxy.UseDefaultCredentials = true;

                XmlNode resultNode = listProxy.UpdateListItems("custom1", batchNode);

    http://www.certdev.com

    Marked As Answer byjdxyw Thursday, April 16, 2009 1:35 AM

    Steve.Curran  Wednesday, April 15, 2009 3:43 PM

    To Store values to User Field and URL Field, we have to store in differentformat.

    Because the The User Field is a Lookup Field, getting value from User Information List. The URL Field contains two values, one for URL and another one for URL Description.

    User Field Format: [ID];#[User Login Name]

    URL Field Format: [URL], [URL Description]

    Below i give the sample code for addng new list item with URL and User Fields,

    UserGroupWebService.UserGroup ugService=new UserGroupWebService.UserGroup();

    ListsWebService.Lists lService=new ListsWebService.Lists();

    //Get User ID from User Login Name

    XmlNode ugNode=ugService.GetUserInfo("Server\\LoginName");

    XmlDocument ugdoc = new XmlDocument();

    ugdoc.LoadXml(ugNode.OuterXml);

    XmlNodeList ugList = ugdoc.GetElementsByTagName("User");

    string id = ugList[0].Attributes["ID"].Value;

    //Build the xml for adding new list item

    string strBatch = @"<Method ID='1' Cmd='New'>

    <Field Name='Title'>Sample Title</Field>

    <Field Name='UserName'>" + id + @";#SERVER\\LoginName</Field>

    <Field Name='SampleUrl'>http://www.microsoft.com, Microsoft Site</Field>

    </Method>";

    XmlDocument xmlDoc = new System.Xml.XmlDocument();

    System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");

    elBatch.InnerXml = strBatch;

    //Addding item to the List

    XmlNode ndReturn = lService.UpdateListItems("<List Name>", elBatch);

    Before coding add the (~site/_vti_bin/Lists.asmx and ~site/_vti_bin/UserGroup.asmx) webservices as references.

    SPFieldUrlValue urlValue = new SPFieldUrlValue();

                        urlValue.Url = items.First().Value.ToString();

                        urlValue.Description = "Link";

                        itemValue =  urlValue.ToString();

    http://www.sharepointdev.net/sharepoint--development-programming/how-to-use-web-service-to-add-a-new-item-which-has-a-hyperlink-column-a-user-column-53394.shtml

  • 相关阅读:
    Python eval 函数妙用
    502与504故障分析与解决方法
    [转]谈谈select, iocp, epoll,kqueue及各种网络I/O复用机制
    计算阶乘n!末尾0的个数
    C++中的Overload、Override和Overwrite
    C++中的空类与空结构体大小
    多线程编程之优先级翻转问题
    数据库原理之事务(二)
    数据库原理之事务(一)
    NoSQL之基础篇
  • 原文地址:https://www.cnblogs.com/mingle/p/2807695.html
Copyright © 2020-2023  润新知