using System;
using
using System.IO; using System.Linq; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Office2013.Excel; using Microsoft.SharePoint.Client; // The following using directive resolves the ambiguity // between the System.IO.File class and Microsoft.SharePoint.Client.File // class. using ClientOM = Microsoft.SharePoint.Client; using System.Net; using System.Data;
class Program { static private void CopyStream(Stream source, Stream destination) { byte[] buffer = new byte[32768]; int bytesRead; do { bytesRead = source.Read(buffer, 0, buffer.Length); destination.Write(buffer, 0, bytesRead); } while (bytesRead != 0); }
static System.IO;
usingvoid System.Linq;
usingMain(string[] DocumentFormat.OpenXml.Packaging;args)
using DocumentFormat.OpenXml.Wordprocessing;{
using Microsoft.SharePoint.Client;
// The following usingNetworkCredential directivecred resolves= thenew ambiguityNetworkCredential("USERNAME", "PASS", "WINAD");
// between the System.IO.File classstring andSPSite Microsoft.SharePoint= "https://www.ClientCOMPANYPORTAL.FileCOM";
string DirStruc = "/sp/CorporateITPro/BusinessDocuments/Migration/Templates/Master"; class.
using ClientOM = Microsoft.SharePoint.Client;
using System.Net;
using System.Data;
class Program
{
staticstring privatedFile void= CopyStream(Stream"MigClassification.xslx";
source, Stream destination)
{
byte[]ClientContext bufferclientContext;
clientContext = new byte[32768];ClientContext(SPSite);
intclientContext.Credentials bytesRead;= cred;
do
{Web spWebsite;
spWebsite = clientContext.Web;
List bytesReadlist = sourceclientContext.Read(buffer, 0, bufferWeb.LengthLists.GetByTitle(dFile);
destination.Write(buffer,
0, bytesRead CamlQuery camlQuery = new CamlQuery();
} whilecamlQuery.ViewXml =(bytesRead"<View !=Scope='RecursiveAll'><Query><Where><Neq><FieldRef 0Name='ContentType' /><Value Type='Text'>Folder</Value></Neq></Where></Query></View>");
} camlQuery.FolderServerRelativeUrl = DirStruc;
static void Main(string[] args ListItemCollection listItems = list.GetItems(camlQuery);
{
string SPSite = "https://www clientContext.remotewebisteLoad(listItems, items => items.com";Include(
string dFile = "FileIWantToGet item => item.xlsx";File.Name,
// a hard coded variable at the momnent.item => item.File.
Author,
ClientContext _clientContext;
Web _spWebsite;
NetworkCredential cred = new NetworkCredential("user item => item.name"File.ServerRelativeUrl,
"somePassword" item => item["Proposalx0020Navigationx0020Grouping"],
"RemoteDomain" item => item["Modified"]);
_clientContext = new ClientContext(SPSite );
_clientContext.Credentials
= cred;
_spWebsite = _clientContext.Web;try
{
List list = _spWebsite.Lists clientContext.GetByTitleExecuteQuery(dFile);// NOT FOUND ERROR HERE
CamlQuery camlQuery = new CamlQuery if (listItems != null);
camlQuery.ViewXml = @"<View Scope='RecursiveAll'><Query><Where> {
foreach (Microsoft.SharePoint.Client.ListItem item in listItems)
<BeginsWith><FieldRef Name='FileDirRef'/>
{
item.File.CheckOut();
<Value Type='Text'>/subdir0/subdir1/subdir2/subdir3/" + dFile + @"</Value> clientContext.ExecuteQuery();
// GET SOME DATA RELATED TO THE FILE FROM </BeginsWith></Where></Query></View>";A DB
//camlQuery.FolderServerRelativeUrl =PUT "/";
ListItemCollectionDATA listItemsIN =THE list.GetItems(camlQuery);FILE
_clientContext.Load(listItems, items => items.Include(
item => item.File.Name,
item => item.File.ServerRelativeUrlCheckIn("", CheckinType.MajorCheckIn);
item => item["Proposal_x0020_Navigation_x0020_Grouping"],
item => item["Modified"]));
_clientContext clientContext.ExecuteQuery();//
Errors as con't find dfile file
if (listItems != null)
{
foreach}
(Microsoft.SharePoint.Client.ListItem item in listItems)
{}
}
item.CheckOutcatch ();Exception ex)
{
// shove some data inif it(System.Diagnostics.Debugger.IsAttached and==
true)
item.CheckIn();{
Console.WriteLine(itemex.DisplayNameMessage);
}
}
}
}
}