Every step SharePoint development study notes Serial X, SharePoint web service development (under)

Overview

Next we introduce Lists.UpdateListItems update item usage practices and UserGroup.GetUserCollectionFromSite (), first learning every step SharePoint Development Learning Notes Series Octal, SharePoint web service development (on), you will be easier to study the development of web service

Lists.UpdateListItems usage

Updated common list of item of xml format

<Batch OnError="Continue" ListVersion="1" 
ViewName="270C0508-A54F-4387-8AD0-49686D685EB2">
   <Method ID="1" Cmd="Update">
      <Field Name="ID">4<Field>
      <Field Name="Field_Name">Value</Field>
   </Method>
   <Method ID="2" Cmd="Update">
      <Field Name="ID" >6</Field>
      <Field Name="Field_Name">Value</Field>
   </Method>
</Batch>

Updated item folder of xml format

<Batch OnError="Continue" PreCalc="TRUE" 
ListVersion="0" 
ViewName="{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}">
   <Method ID="1" Cmd="Update">
      <Field Name="ID">3</Field>
      <Field Name="owshiddenversion">1</Field>
      <Field Name="FileRef">
         http://Server/[sites/][Site/]Shared 
         Documents/Folder</Field>
      <Field Name="FSObjType">1</Field>
      <Field Name="BaseName">Name</Field>
   </Method>
</Batch>

Update documents in xml format of the item

<Batch OnError="Continue" PreCalc="TRUE" 
ListVersion="0" 
ViewName="{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}">
   <Method ID="1" Cmd="Update">
      <Field Name="ID">2</Field>
      <Field Name="owshiddenversion">1</Field>
      <Field Name="FileRef">
         http://Server/[sites/][Site/]Shared 
         Documents/File</Field>
      <Field Name="BaseName">Name</Field>
   </Method>
</Batch>

We deal with xml format is updated item

        /// <summary>
        /// Get the approved XML Node that will be used for the insert method of the webservice
        /// </summary>
        /// <param name="batch"></param>
        /// <returns></returns>
        private XmlNode GetUpdateXmlNode(List<ListItemBE> batch)
        {
            StringBuilder xml = new StringBuilder();

            xml.Append(@"<Batch OnError=""Continue"">");
            foreach (ListItemBE listItem in batch)
            {
                xml.AppendFormat(@"<Method ID=""{0}"" Cmd=""Update"">", listItem.Id);
                xml.Append(GetFieldInnerXml(listItem));
                xml.Append("</Method>");
            }
            xml.Append("</Batch>");

            //Get the Batch node
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml.ToString());

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

Sharepoint call when updating item web service processing

        /// <summary>
        /// Insert the items
        /// </summary>
        /// <param name="batch"></param>
        /// <returns></returns>
        private UpdateResultBE UpdateItems(List<ListItemBE> batch)
        {
            //Get the Insert XML Node
            XmlNode batchNode = GetUpdateXmlNode(batch);
            XmlNode result = null;

            _logger.Log("Started batch updating list Items");
            try
            {
                //Call the webservice
                result = _ws.UpdateListItems(_listProperty.ListName, batchNode);
            }
            catch (Exception ex)
            {
                _logger.Log(String.Format("Error updating Items. Exception: {0}. Stack Trace: {1}", ex.Message, ex.StackTrace));
            }

            _logger.Log("Finished batch updating list items");

            //Transform the result into an object

            UpdateResultBE insertResult = new UpdateResultBE(result, _listProperty);
            LogInsertResult(insertResult);

            return insertResult;
        }

UserGroup.GetUserCollectionFromSite用法

Firstly, the web service connector, as follows

        public static SPUserGroupWS.UserGroup GetUserGroupWebService(ListBE listProperty)
        {
            string wsUrl = GetWSUrl(listProperty) + "_vti_bin/usergroup.asmx";
            SPUserGroupWS.UserGroup ws = new SPUserGroupWS.UserGroup();
            ws.Url = wsUrl;
            ws.UseDefaultCredentials = true;
            ws.Credentials = WSHelper.GetCredentials(listProperty.Type);
            return ws;
        }

We only take two simple fields to be a model

    public class UserInfoBE
    {
        public string ID { get; set; }
        public string NTLoginName { get; set; }
    }

Method for obtaining site user list

        public List<UserInfoBE> GetUserInfoList()
        {
            List<UserInfoBE> userInfoList = new List<UserInfoBE>();
            UserInfoBE listItem;

            XmlNode nodes = ws.GetUserCollectionFromSite();
            foreach (XmlNode node in nodes)
            {
                if (node.Name == "Users")
                {
                    for (int i = 0; i < node.ChildNodes.Count; i++)
                    {
                        if (node.ChildNodes[i].Name == "User")
                        {
                            listItem = new UserInfoBE();
                            listItem.ID = node.ChildNodes[i].Attributes["ID"].Value;
                            listItem.NTLoginName = node.ChildNodes[i].Attributes["LoginName"].Value;
                            userInfoList.Add(listItem);
                        }
                    }
                }
            }
            return userInfoList;
        }

So that you can get a list of sites the user information through the web service, but it should be noted that, web service user name and password must be an administrator sharepoint site.

to sum up

Institute of sharepoint web service user is doing very helpful when you migrate sharepoint site data.

Author: the Spring Yang

Source: http://www.cnblogs.com/springyangwc/

This article belongs to the author and blog Park total, welcome to reprint, but without the author's consent declared by this section must be retained, and given the original connection in the apparent position of the article page, otherwise the right to pursue legal responsibilities.

Reproduced in: https: //www.cnblogs.com/springyangwc/archive/2011/08/01/2124186.html

Guess you like

Origin blog.csdn.net/weixin_34308389/article/details/93340940