0

有没有人有关于如何通过 .Net 中的 Sharepoint Web 服务访问 sharepoint 文档库的代码

如果您进行谷歌搜索,代码是可用的,但它们都不起作用。

这是我正在尝试的代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;
using System.Web;
using System.Web.Services;
using System.IO;
using System.Net;


namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            XmlDocument xmldoc = new System.Xml.XmlDocument();

            string URL = "";

            string FileName = "";

            DownloadListItems.Lists objLists = new EncryptAndDecrypt.DownloadListItems.Lists();

            objLists.Credentials = System.Net.CredentialCache.DefaultCredentials;

            objLists.Url = "{siteurl}/_vti_bin/lists.asmx";

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

            XmlNode xmlQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");

            XmlNode xmlViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");

            XmlNode xmlQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");

            xmlQueryOptions.InnerXml = "<ViewAttributes Scope='RecursiveAll' IncludeRootFolder='True' />";

            xmlViewFields.InnerXml = "";

            xmlQuery.InnerXml = "";

            try
            {

                XmlNode xmlListItems = objLists.GetListItems("Shared Documents", null, xmlQuery, xmlViewFields, null, xmlQueryOptions, null); //change the document library name to your document library

                XmlNodeList oNodes = xmlListItems.ChildNodes;

                foreach (XmlNode node in oNodes)
                {
                    XmlNodeReader Reader = new XmlNodeReader(node);

                    while (Reader.Read())
                    {
                        if (Reader["ows_EncodedAbsUrl"] != null && Reader["ows_LinkFilename"] != null)
                        {
                            URL = Reader["ows_EncodedAbsUrl"].ToString();

                            FileName = Reader["ows_LinkFilename"].ToString();

                            CopyAndSaveAttachment(URL, FileName);
                        }

                    }

                }

                Console.ReadLine();
            }

            catch (System.Web.Services.Protocols.SoapException ex)
            {
                throw ex;
            }

        }

        public static void CopyAndSaveAttachment(string URL, string FileName)
        {

            HttpWebRequest request;

            HttpWebResponse response = null;

            try
            {

                request = (HttpWebRequest)WebRequest.Create(URL);

                request.Credentials = System.Net.CredentialCache.DefaultCredentials;

                request.Timeout = 10000;

                request.AllowWriteStreamBuffering = false;

                response = (HttpWebResponse)request.GetResponse();

                Stream s = response.GetResponseStream();

                //Write to disk

                FileStream fs = new FileStream(@"C:\DownLoads\" + FileName, FileMode.Create);

                byte[] read = new byte[4096];

                int count = s.Read(read, 0, read.Length);

                while (count > 0)
                {

                    fs.Write(read, 0, count);

                    count = s.Read(read, 0, read.Length);

                }

                //Close everything

                fs.Close();

                s.Close();

                response.Close();

            }

            catch (Exception ex)
            {
                throw ex;

            }

        }
    }
}

我得到的错误是:错误 1 ​​找不到类型或命名空间名称“DownloadListItems”(您是否缺少 using 指令或程序集引用?) c:\users\fox7lsh\documents\visual studio 2010\Projects\ WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 36 13 WindowsFormsApplication2

问候

4

0 回答 0