0

.Net で SharePoint Web サービスを介して SharePoint ドキュメント ライブラリにアクセスする方法に関するコードを持っている人はいますか?

Google検索を行うとコードが利用可能ですが、どれも機能していません。

これは私が試しているコードです

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