Wednesday, April 19, 2017

client object model - CSOM move the files one folder another folder - SharePoint Stack Exchange

client object model - CSOM move the files one folder another folder - SharePoint Stack Exchange:



There is no built-in method in SharePoint CSOM API for moving Folder with Files from one location into another.
The following solution demonstrates how to move files from source folder into destination folder:
public static class FolderExtensions
{


    public static void MoveFilesTo(this Folder folder, string folderUrl)
    {
        var ctx = (ClientContext)folder.Context;
        if (!ctx.Web.IsPropertyAvailable("ServerRelativeUrl"))
        {
            ctx.Load(ctx.Web, w => w.ServerRelativeUrl);   
        }
        ctx.Load(folder, f => f.Files, f => f.ServerRelativeUrl, f => f.Folders);
        ctx.ExecuteQuery();

        //Ensure target folder exists
        ctx.Web.EnsureFolder(folderUrl.Replace(ctx.Web.ServerRelativeUrl, string.Empty));
        foreach (var file in folder.Files)
        {
            var targetFileUrl = file.ServerRelativeUrl.Replace(folder.ServerRelativeUrl, folderUrl);
            file.MoveTo(targetFileUrl, MoveOperations.Overwrite);
        }
        ctx.ExecuteQuery();

        foreach (var subFolder in folder.Folders)
        {
            var targetFolderUrl = subFolder.ServerRelativeUrl.Replace(folder.ServerRelativeUrl,folderUrl);
            subFolder.MoveFilesTo(targetFolderUrl);
        }
    }

}

static class WebExtensions
{
    /// <summary>
    /// Ensures whether the folder exists   
    /// </summary>
    /// <param name="web"></param>
    /// <param name="folderUrl"></param>
    /// <returns></returns>
    public static Folder EnsureFolder(this Web web, string folderUrl)
    {
        return EnsureFolderInternal(web.RootFolder, folderUrl);
    }


    private static Folder EnsureFolderInternal(Folder parentFolder, string folderUrl)
    {
        var ctx = parentFolder.Context;
        var folderNames = folderUrl.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
        var folderName = folderNames[0];
        var folder = parentFolder.Folders.Add(folderName);
        ctx.Load(folder);
        ctx.ExecuteQuery();

        if (folderNames.Length > 1)
        {
            var subFolderUrl = string.Join("/", folderNames, 1, folderNames.Length - 1);
            return EnsureFolderInternal(folder, subFolderUrl);
        }
        return folder;
    }
}
Key points:
  • allows to ensure whether destination folder(s) exists
  • In case of nested folders, its structure is preserved while moving files
Usage
var srcFolderUrl = "/news/pages";
var destFolderUrl = "/news/archive/pages";
using (var ctx = new ClientContext(url))
{      
    var sourceFolder = ctx.Web.GetFolderByServerRelativeUrl(srcFolderUrl);
    sourceFolder.MoveFilesTo(destFolderUrl);
    sourceFolder.DeleteObject(); // delete source folder if nessesary
    ctx.ExecuteQuery();
}


'via Blog this'

Amazon.com: Dell Precision M4600 Intel Quad 2820QM 2.3GHz 32GB RAM 1TB HDD DVDRW Windows 7 Professional 64-bit 15.6" 1920x1080 HD Ultra Sharp LED Display nVidia Quadro FX 1000M 2GB Dedicated RAM Memory Video Card Without Integrated Web Camera: Computers & Accessories

Amazon.com: Dell Precision M4600 Intel Quad 2820QM 2.3GHz 32GB RAM 1TB HDD DVDRW Windows 7 Professional 64-bit 15.6" 1920x1080 HD Ultra Sharp LED Display nVidia Quadro FX 1000M 2GB Dedicated RAM Memory Video Card Without Integrated Web Camera: Computers & Accessories:



Dell Precision M4600 Intel Quad 2820QM 2.3GHz 32GB RAM 1TB HDD DVDRW Windows 7 Professional 64-bit 15.6" 1920x1080 HD Ultra Sharp LED Display nVidia Quadro FX 1000M 2GB Dedicated RAM Memory Video Card Without Integrated Web Camera




Available from these sellers.
  • Dell Precision M4600 Ultrapowerful Mobile Workstation
  • 15.6" 1920x1080 Full HD Anti-Glare LED Display
  • Intel Quad Core i7 2820QM 2.30GHz Processor
  • nVidia Quadro Video Card with 2GB Dedicated RAM Memory
  • Windows 7 Professional 64-bit operating system






'via Blog this'

Monday, April 10, 2017

c# - How to download/upload files from/to SharePoint 2013 using CSOM? - Stack Overflow

c# - How to download/upload files from/to SharePoint 2013 using CSOM? - Stack Overflow: "
Upload a file

Upload a file to a SharePoint site (including SharePoint Online) using File.SaveBinaryDirect Method:

using (var clientContext = new ClientContext(url))
{
using (var fs = new FileStream(fileName, FileMode.Open))
{
var fi = new FileInfo(fileName);
var list = clientContext.Web.Lists.GetByTitle(listTitle);
clientContext.Load(list.RootFolder);
clientContext.ExecuteQuery();
var fileUrl = String.Format("{0}/{1}", list.RootFolder.ServerRelativeUrl, fi.Name);

Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, fileUrl, fs, true);
}
}
Download file

Download file from a SharePoint site (including SharePoint Online) using File.OpenBinaryDirect Method:

using (var clientContext = new ClientContext(url))
{

var list = clientContext.Web.Lists.GetByTitle(listTitle);
var listItem = list.GetItemById(listItemId);
clientContext.Load(list);
clientContext.Load(listItem, i => i.File);
clientContext.ExecuteQuery();

var fileRef = listItem.File.ServerRelativeUrl;
var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, fileRef);
var fileName = Path.Combine(filePath,(string)listItem.File.Name);
using (var fileStream = System.IO.File.Create(fileName))
{
fileInfo.Stream.CopyTo(fileStream);
}
}"



'via Blog this'

Review Lenovo IdeaPad Y560 Notebook - NotebookCheck.net Reviews

Review Lenovo IdeaPad Y560 Notebook - NotebookCheck.net Reviews: "Review Lenovo IdeaPad Y560 Notebook
Sebastian Jentsch, 08/08/2010
Gaming revamped. Lenovo is well known for robust ThinkPads and low-priced office laptops. But a gamer with ATI HD 5730, Core i7-720QM, 7200 rpm hard disk and JBL loudspeakers?! The aggressive price of the Y-model: 860 Euro."



VJ: The review is extensive covered all major areas (*****)



'via Blog this'

Thursday, January 20, 2011

Lenovo - Laptop computers - ThinkPad W510

Lenovo - Laptop computers - ThinkPad W510: "Shop ThinkPad W510

These series of laptops are good for running SharePoint 2010 VM's locally.

Monday, December 27, 2010

Newegg.com - Samsung 24" 1920x1080 5ms B2430HD HD HDMI WideScreen LCD Monitor w/TV Tuner & USB Port 300 cd/m2 70,000:1

Newegg.com - Samsung 24" 1920x1080 5ms B2430HD HD HDMI WideScreen LCD Monitor w/TV Tuner & USB Port 300 cd/m2 70,000:1: "Samsung 24' 1920x1080 5ms B2430HD HD HDMI WideScreen LCD Monitor w/TV Tuner & USB Port 300 cd/m2 70,000:1"

Note: Nanda had this..as per his inputs its good.