通过 Web 服务访问 Sharepoint 任务? [英] Accessing Sharepoint tasks via web services?

查看:60
本文介绍了通过 Web 服务访问 Sharepoint 任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经查看了很多之前关于共享点和通过 Web 服务访问对象的问题,我非常确信可以通过 Lists 界面访问任务.

I've looked at a lot of the previous questions asked about sharepoint and accessing objects via web-services, and I am pretty convinced that tasks can be accessed through the Lists interface.

有人可以帮我验证一下吗?

Can anybody please verify this for me?

另外,如果有人有这方面的任何例子,我将不胜感激.我不是 Sharepoint 专家,但我需要连接到实例才能检索任务对象.

Also, if anyone has any examples of this I would be very grateful. I'm not a Sharepoint guy but I need to connect to an instance just to retrieve task objects.

推荐答案

假设你想要一个使用 Visual Studio 和 C# 的代码解决方案

Assuming you want a code solution using Visual Studio and C#

向您的 SharePoint 列表 Web 服务添加网络参考[http://[server-url]/_vti_bin/lists.asmx]

Add a web reference to your SharePoint List Web Service [http://[server-url]/_vti_bin/lists.asmx]

创建一个类似于下面的新类:

Create a new class similar to the one below:

using System;
using System.Text;
using System.Xml;
using System.Text.RegularExpressions;
using System.Net;            

public class SharePointList
{

   public void ReadSharePointList()
   {
    SPList.Lists listService = new SPList.Lists();

            try
            {
                // Retreive the URL to the list web service from the application cache
                listService.Url = "http://[server-url]/_vti_bin/Lists.asmx";
                // Retreive the GUID for the sharepoint list
      // To find the GUID for your list, navigate to your SharePoint list and select Settings > List Settings.
      // The browser url will display http://[server-url]/_layouts/listedit.aspx?List=%7B7A4C9C52%2DE7E7%2D4582%2D926E%2DC70D048F9071%7D
      // The %7B7A4C9C52%2DE7E7%2D4582%2D926E%2DC70D048F9071%7D is your GUID that you need to transform 
      // %7B = {
      // %2D = -
      // %7D = }
      // e.g. %7B7A4C9C52%2DE7E7%2D4582%2D926E%2DC70D048F9071%7D = {7A4C9C52-E7E7-4582-926E-C70D048F9071}

                string listName = {YOUR LIST GUID HERE};

                // SharePoint Web Serices require authentication
                string serviceAccountID = [USERID];
                string serviceAccountPW = [PASSWORD];
                listService.Credentials = new NetworkCredential(serviceAccountID, serviceAccountPW);

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

                XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element,"Query","");
                XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element,"ViewFields","");
                XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element,"QueryOptions","");

                ndQueryOptions.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>" + 
                                          "<DateInUtc>TRUE</DateInUtc>";

                ndViewFields.InnerXml = "<FieldRef Name=\"Title\" />" +
                                        "<FieldRef Name=\"Search_x0020_Value\" />";

                // Form a query for the list items where Start Date is null or <= today's date
                ndQuery.InnerXml = "<Where>" +
                                    "<Or>" +
                                    "<IsNull><FieldRef Name=\"Start_x0020_Date\"/></IsNull>" +
                                    "<Leq><FieldRef Name=\"Start_x0020_Date\"/><Value Type=\"DateTime\"><Today/></Value></Leq>" +
                                    "</Or>" +
                                    "</Where>" +
                                    "<OrderBy><FieldRef Name=\"Sort_x0020_Order\" Ascending=\"TRUE\" /></OrderBy>";

                XmlNode ndListItems = listService.GetListItems(listName, null, ndQuery, ndViewFields, null, ndQueryOptions, null);

                foreach (XmlNode node in ndListItems)
                {
                    if (node.Name == "rs:data")
                    {
                        for (int f = 0; f < node.ChildNodes.Count; f++)
                        {
                            if (node.ChildNodes[f].Name == "z:row")
                            {
                                   //DO SOMETHING WITH YOUR RESULTS
                                string test = node.ChildNodes[f].Attributes["ows_Title"].Value, node.ChildNodes[f].Attributes["ows_Search_x0020_Value"].Value;
                            }
                        }
                    }
                }
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
           //HANDLE ERRORS
            }
   }
}

这篇关于通过 Web 服务访问 Sharepoint 任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆