vendredi 23 janvier 2015

Code behaving different between 2 different sharepoint sites



I am working on a c# app to download files from a SharePoint 2010 directory (file list I believe is the proper term for sharepoint but I have only picked that up and am not 100% sure. can some one confirm I have the right terminology?)


I have the following code which works for one site using Microsoft.Sharepoint.Client:



ClientContext context = new ClientContext(sourcePath.Site);
Web web = context.Web;
Folder spfolder = web.GetFolderByServerRelativeUrl(sourcePath.Folder);
FileCollection files = spfolder.Files;

context.Load(context.Web);
context.Load(spfolder);
context.Load(files);
context.ExecuteQuery();

foreach (File file in files)
{
destfile = System.IO.Path.Combine(move.FileDest, file.Name);
FileInformation f = File.OpenBinaryDirect(context, file.ServerRelativeUrl);

using (var fileStream = new System.IO.FileStream(destfile, System.IO.FileMode.Create))
{
f.Stream.CopyTo(fileStream);
}
}


On another site (same server) the same code does not work as the files collection returns an empty enumeration when there are files in the sharepoint folder (which can be interacted with through the web app UI).


The weird part is when I look at spfolder the ItemCount is correct (5, one sub folder and 4 files) so I am unsure what is going on.


For permissions I have read only on the site where the code works and Full Control on the site where the code will not work.


If any one can point me in the direction to look I would be grateful as I am a complete sharepoint noob.








0 commentaires:

Enregistrer un commentaire