title: Access Sharepoint Document Library through Sharepoint Web Services
body: <p>Does anyone have code on how to access sharepoint document library through Sharepoint Web Services in .Net</p>
  
  <p>Code is available if you do google search but none of them is working.</p>
  
  <p>This is the code I'm trying</p>
  
  <pre><code>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 = "&lt;ViewAttributes Scope='RecursiveAll' IncludeRootFolder='True' /&gt;";
  
              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 &amp;&amp; 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 &gt; 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;
  
              }
  
          }
      }
  }
  </code></pre>
  
  <p>Error which I'm getting is:
  Error   1   The type or namespace name 'DownloadListItems' could not be found (are you missing a using directive or an assembly reference?) c:\users\fox7lsh\documents\visual studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs   36  13  WindowsFormsApplication2</p>
  
  <p>Regards</p>