Sharepoint client object model - Pull files from one site and move to another

Dear All,
I am using client object model to retrieve files of certain criteria using caml query and copy them to some other site using 
client object model. There is no exception being thrown, but the application is not performing either. No files are being copied to destination. Here is the code. Please advise.
The message box that I have kept at the end is being displayed, but no files are being copied.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Net;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint;
using SP = Microsoft.SharePoint.Client;
namespace WindowsFormsApplication2
    public partial class Form1 : Form
        public Form1()
            InitializeComponent();
        private void Form1_Load(object sender, EventArgs e)
        private void button1_Click(object sender, EventArgs e)
            SP.ClientContext srcContext = new SP.ClientContext(textBox1.Text);
            srcContext.Credentials = new NetworkCredential(textBox3.Text, textBox4.Text, textBox5.Text);
            SP.ClientContext destContext = new SP.ClientContext(textBox2.Text);
            destContext.Credentials = new NetworkCredential(textBox3.Text, textBox4.Text, textBox5.Text);
            SP.CamlQuery camlQuery = new SP.CamlQuery();
            camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query><Where><And><Geq><FieldRef Name='Created' /><Value IncludeTimeValue='TRUE' Type='DateTime'>2013-01-01T04:16:20Z</Value></Geq><And><Lt><FieldRef
Name='Created' /><Value IncludeTimeValue='TRUE' Type='DateTime'>2013-12-31T04:16:43Z</Value></Lt><Or><Eq><FieldRef Name='Document_x0020_Classification' /><Value Type='Choice'></Value></Eq><Eq><FieldRef
Name='Document_x0020_Classification' /><Value Type='Choice'>Case Studies</Value></Eq></Or></And></And></Where></Query></View>";
            SP.Web oWebsite = srcContext.Web;
            srcContext.Load(oWebsite, website => website.Webs);
            srcContext.ExecuteQuery();
            SP.Web dWebsite = destContext.Web;
            destContext.Load(dWebsite);
            destContext.ExecuteQuery();
            foreach (SP.Web web in oWebsite.Webs)
                MessageBox.Show(web.Title);
                foreach (SP.List list in web.Lists)
                    if (list.BaseType.ToString() == "DocumentLibrary")
                        MessageBox.Show(list.Title);
                        SP.ListItemCollection collListItem = list.GetItems(camlQuery);
                        srcContext.Load(collListItem);
                        srcContext.ExecuteQuery();
                        foreach (var doc in collListItem)
                                    SP.File f = doc.File;
                                    srcContext.Load(f);
                                    srcContext.ExecuteQuery();
                                    string destLibrary = "shared Documents";
                                    string nLocation = dWebsite.ServerRelativeUrl.TrimEnd('/') + "/" + destLibrary.Replace(" ", "")
+ "/" + f.Name;
                                    SP.FileInformation fileInfo = SP.File.OpenBinaryDirect(srcContext, f.ServerRelativeUrl);
                                    SP.File.SaveBinaryDirect(destContext, nLocation, fileInfo.Stream, true);
            MessageBox.Show("Completed");
sk.Rakhishma

Hi,
To copy files from one site collection to another site collection, the simplest way is to open document library in windows explorer view.
Go to document library, click library tab, click open with explorer.
You can open the document library1 in explorer then copy the files which you want to paste to another site collection
document library2, then open the document library2 in explorer to paste the documents.
Besides, there are other method:
https://social.msdn.microsoft.com/Forums/office/en-US/67282348-25c7-4bd0-9d95-61024c6892f9/how-we-move-a-document-library-from-one-site-collection-to-another-sitecollection?forum=sharepointgeneralprevious
https://social.msdn.microsoft.com/Forums/sharepoint/en-US/8c112d85-1ab8-426b-be37-d010cf8647fe/copy-a-list-from-one-site-collection-to-another-using-web-service
Best Regards,
Lisa Chen
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected]

Similar Messages

  • Print multiple documents in sharepoint client object model

    Hi  All,
    I  have a content editor webpart which displays documents from document library using sharepoint client object model. 
    test1 test2 test3 test4 are documents from document library.
    I have requirement to print the selected documents in single click of print button.
    once I clicks on print button all the selected documents should get printed.
    Is there any way to achieve this....?
    Regards
    Srinivas
    srinivas

    Hi Srinivas,
    You can do this but it will be combination of ECMA and JS. First you need to get selected file name by ECMA script then call a java script function to print documents.
    Here is script to print all docs: http://stackoverflow.com/questions/7187400/printing-multiple-pdf-files-using-javascript
    Hope it could help
    Hemendra: "Yesterday is just a memory,Tomorrow we may never see"
    Whenever you see a reply and if you think is helpful, click "Vote As Helpful"! And whenever
    you see a reply being an answer to the question of the thread, click "Mark As Answer

  • Using Sharepoint Client Object Model with large libraries (more than 5000 elements)

    Hi,
    i have issue with acccessing large list with more than 5000 elements. I use a Sharepoint Client Object Model. 
    It worked till yesterday when in the list was less than 5000. Now there is in the library more than 5000 elements. I have changed in the Central Administration limit for list from 5000 to 10000, but it helped only for list views. Script returns now 0 records.
    var clientContext = new SP.ClientContext.get_current();
    var currentListId =_spPageContextInfo.pageListId;
    oList = clientContext.get_web().get_lists().getById(currentListId);
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View Scope=\"RecursiveAll\">'+
    '<Query>'+
    '<Where>'+
    '<And>'+
    '<Eq><FieldRef Name=\"ContentTypeId\"/><Value Type=\"Text\">'+contentTypeId+'</Value></Eq>'+
    '<And>'+
    '<Eq><FieldRef Name=\"_x0040_Client\" LookupId=\"TRUE\" /><Value Type=\"Lookup\">'+client+'</Value></Eq>'+
    '<Eq><FieldRef Name=\"_x0040_Company\" LookupId=\"TRUE\" /><Value Type=\"Lookup\">'+organisation+'</Value></Eq>'+
    '</And>'+
    '</And>'+
    '</Where>'+
    '</Query>'+
    '<ViewFields>'+
    '<FieldRef Name=\"ID\" />'+
    '</ViewFields>'+
    '</View>'+
    '<RowLimit>100</RowLimit>');
    camlQuery.ViewAttributes = "Scope='RecursiveAll'";
    listItems = oList.getItems(camlQuery);
    clientContext.load(listItems);
    clientContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));
    Please advice how i can resolve this issue. Thanks a lot!!
    from MSDN forum...

    Thanks you, friends!
    That to resolve my issue, i made next things:
    1) turn off a limit items for my list
    2) used SPQuery.ListItemCollectionPosition
    property,
    3) and corrected little mistake in my CAML Query.
    May be a punkt #2 will be enough, don't you :)
    from MSDN forum...

  • How to get all previous versions page contents of a publishing page using SharePoint Client Object Model 2010

    How to get all previous versions page contents and other field values of a publishing page using SharePoint Client Object Model 2010?
    Thanks,
    Osmita

    Hi Osmita,
    Greetings.
    Here are the links that helps you. It has code attached to it.
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/a0d2ab40-99ba-4368-8505-1dc559ef6469/get-content-of-previous-version-of-page-sharepoint-2010?forum=sharepointgeneralprevious
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/faaf419f-997e-4150-9911-48cc375c3b46/how-to-get-previous-published-versions-of-publishing-pages-in-sharepoint-2010?forum=sharepointdevelopmentprevious
    Please remember to click 'Mark as Answer' on the answer if it helps you

  • Through SharePoint Client Object model, how to make color coded events on Sharepoint Calendar

    Hi,
    Through SharePoint Client Object model, how to make color coded events on Sharepoint Calendar.
    Plese share your knowledge.
    Regards
    Tharak

    Hi,
    According to your post, my understanding is that you wanted to make a color events Calendar.
    We can achieve it using the OOB method by creating the Calendars Overlay.
    http://summit7systems.com/color-code-calendar-events-in-sharepoint/
    You can also use the JavaScript to achieve it.
    http://spsawyer.wordpress.com/2013/07/18/sharepoint-color-calendar/
    http://www.planetwilson.co.uk/sharepoint-2013-colour-calendar-v2/
    more reference:
    http://usermanagedsolutions.com/SharePoint-User-Toolkit/Pages/Color-Coding-Calendar-List.aspx
    http://blog.pathtosharepoint.com/2010/04/06/tutorial-add-color-coding-to-your-sharepoint-2007-calendar-in-15-minutes/#comment-7231
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • How do I move all my files from one User Profile (account) into another? I needed to create a new account and want all of my files accessible in the new one.

    How do I move all my files from one User Profile (account) into another?
    I needed to create a new account and want all of my files accessible in the new one.

    ok, what you're learning right now is 101 unix, which is good. Unix is a good thing
    now: the way unix works, and macos (which uses unix underneath) the files and folders work like a hierarchy.
    the start of that tree is /
    so, if you were to do:
    cd /
    (cd means change directory)
    it will bring you at the highest branch of the file system.
    cd /Users
    will bring you to where all the users are.
    to see whats in /Users you can use your friend ls command
    ls means list files/directories
    so:
    cd /Users
    ls -la
    (the -la here means show all (even hidden) and long format (very verbose))  this flag is very optional.
    you will see
    fred
    user2
    for example.
    if you want to see the desktop of user2 you would change directory to it then list the files.
    for example:
    cd /Users/user2/Desktop
    Note that the files and directory are case sensitive, so, desktop is NOT the same as Desktop, or DESKTOP
    ls -la
    you should then be able to see everything in users2 desktop
    you could have done as well the same thing in smaller steps, for example:
    cd /
    cd Users
    cd user2
    cd Desktop
    this is the equivalent of cd /Users/user2/Desktop
    So, for your file, i don't know where it was, but know that if you log in as user2, it will directly put you in
    /Users/user2
    which most likely the file you had created from the other user was in /Users/user1
    if you copied all the files from /Users/original_user to /Users/secondUser
    most likely yes, all your mail, bookmarks etc would be copied over.
    so in your case.
    sudo chown -R seconduser:staff /Users/secondUser
    should work
    Remember that if you start a path with the character /  it means start from the root of the file system, at the highest top you can ever get.
    so
    cd /Users/fred
    is not the same as
    cd Users/fred
    unless you were in / already
    i know it may be confusing at first but it's actually very logical if you play with it.
    to simplify, think of it that / means C:\  on windows
    you can't go any higher than C:\  (in a way)
    if you're unsure which directory you're currently in, you can always type:
    pwd
    it will tell you where you are.
    for example:
    cd /
    pwd
    this shows  /
    cd Users
    pwd
    this now shows /Users
    cd /System/Library
    pwd will show /System/Library
    cd /
    cd /Users
    cd fred
    cd Library
    pwd will show /Users/fred/Library
    unix can look very scary but it's actually vital and very necessary to do tasks sometimes that would take for ever to do via the windows. This is good learning.
    so for the myfile you had created, i can't tell you where it is, at the time you created, if you can do a pwd command you'll know the path,
    ls -la  (this shows all the files where you are)
    if you see myfile in the list
    do a pwd
    whatever is return, the real location of the file would be:
    whatever pwd returned / myfile
    I hope that makes sense.

  • How can i copy files from one external hard disk to another using macbook pro with retina display

    How can i copy files from one external hard drive to another using macbook pro with retina display?

    That's odd - if you open Disk Utility (Applications->Utilities) and select the disk(s), how are they formatted? If you're only going to be used with your Mac, they should be formatted as "Mac OS Extended (Journaled)".
    Clinton

  • Count moving object (Inter the ROI from one side and leave ROI from other side)

    Hello All
    I want to design program that can counting moving object that inter ROI from one side and come out from the other side, I want to give each object ID number
    I have design a program that compare between object distances from one frame to the next frame, but the program efficiency is very low
    If any one can give me a sample code that I can use or modify it to suite my application

    Hello,
    you will find the code in the attachment (saved for LV2013). There is a longer delay inside the loop, remove it for efficiency.
    Roughly measuring the time to read an image, the processing takes ~8 ms on my computer (~500x200 image resolution). That is ~125 samples/images per second. Is this not fast enough for you? Considering better image resolution, the time is of course increased.
    My specifications:
    Core i7 3632QM
    6 Gb RAM
    Win 7 x64 (Labview x86 though).
    Best regards,
    K
    https://decibel.ni.com/content/blogs/kl3m3n
    "Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
    Attachments:
    IDMovingObjects.zip ‏64 KB

  • Transfer files from One server(Solaris OS) to another server(Solaris OS)

    Hi,
    I want to Transfer files from One Server(Solaris OS) to another Server(Solaris OS) on private network through ftp and after transferring the files i want to delete these files from first server.
    How can i do that ?
    thanks

    http://commons.apache.org/net/

  • How do you take pictures from one library and put in another library??

    How do you take pictures from one library and put in another library??

    Options:
    1. Export from iPhoto A to the Finder, then import to iPhoto B
    This gets the photo over, but no versions, no edit history and not all the metadata
    2. Use iPhoto Library Manager
    This gets everything: versions, edit history and all the metadata.
    Regards
    TD

  • The remote server returned an error: (401) Unauthorized. while running client context using sharepoint client object model

    Hi,
    I have started using the client object model so that i do not have to go to sharepoint admins to perform some basic operations on remote server. While assigning list item level permission i am getting following error, could you please help. thanks.
    The remote server returned an error: (401) Unauthorized.
       at
    System.Net.HttpWebRequest.GetResponse()
       at
    Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
       at
    Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
       at
    Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
       at
    SetDowntimeItemPermission.SetPermission.Main(String[] args) in

    it seems your request was unauthenticated i'm not sure are you using a web application with FBA or desktop application my suggestion would be try to impersonate your request by passing network credentials (COM works on network credentials )
    NetworkCredential credentials = new NetworkCredential("username", "pwd", "domain");
    ClientContext context = new ClientContext("http://site-url");
    context.Credentials = credentials;
    Best Regards, Ashutosh | SharePoint World

  • I can't copy iTunes media files from one external hard drive to another.

    Hi, I am running the latest iTunes and Mavericks software on my MacBook Pro. My iTunes library is stored on an external Seagate 2tb hard drive and it is almost full. I want to transfer the files to a WD Elements 3tb external hard drive and have made that new volume the destination folder for my iTunes library. However, even though I have enabled read/write on both volumes and made the iTunes media folders on both shared folders, I can't copy all the files from the Seagate drive to the WD drive. It comes up with an error message that says "The operation can't be completed because an unexpected error occurred (error code -8058)". I can transfer files from my MacBook hard drive to the new volume, but can't copy files from the old Seagate volume to my MacBook hard drive; it makes the "boing" sound that indicates it is copying but nothing transfers. Files that won't copy include all music files, some video files and all podcast files. Some transferred with no problem. Any ideas out there?

    Hi Limnos, thanks very much for your reply.
    both external drives came preformatted for Windows but I erased each and reformatted them for Mac before using them.
    i made the destination folder on the new WD drive the new iTunes folder using Advanced preferences in iTunes.
    my original iTunes folder on the first drive contained all my iTunes files, as that, also, was the destination folder that was linked via Advanced preferences.
    If I download new content now with the new drive attached, iTunes has no trouble finding where to place the files.
    in Preferences I have both boxes checked (copy files" and "organize") that deal with copying iTunes files.
    When  I first attempted to copy all iTunes files from one media folder to the other on the external drives, I just did a drag and drop of the whole iTunes media folder from one to the other while both were mounted on my desktop. It started copying immediately with no problems, but as it progressed it started skipping files, each time displaying the error message I reported earlier. that included my entire Music folder. When I open, for example, a season folder that contains files that would not copy, eg, Modern Family Season 5, the episodes that won't copy are there and visible but any attempt to drag and drop them into the correct folder on the new drive results in the error message. There is no pattern to it; it will choose some episodes from some seasons but not others, and no music at all.
    when I look at the "missing" files in  iTunes they have the small exclamation mark that indicates the file is missing, but when I locate it through iTunes it doesn't copy the file on the old external drive to the new one. It just plays it having found the file on the old drive.
    originally I had to make the iTunes folder on the old drive into a shared folder using the Get info window after either a software upgrade or an OS upgrade (I can't remember which, it was several years ago). For some reason the upgrade changed the preferences of that folder to a Read Only folder and after researching the problem found the only way to keep using the drive was to make the folder a shared one. I can't remember why and I apologise for that but it was a long time ago.; I can tell you that at the time it was necessary.
    thanks again for your time; I have a good working knowledge of iTunes and Macs in general so I truly believe I have done everything according to how it should be done,, but clearly I've done something wrong!

  • How do I transfer files from one third party app to another through wifi and without a computer

    How do I transfer files from one third party app directly to another third party app through wifi and without a computer?

    Wifi network
    Email
    Thumb Drive
    Online storage such as, iCloud Google Docs, SkyDrive, etc.

  • How to get the data from one table and insert into another table

    Hi,
    We have requirement to build OA page with the data needs to be populated from one table and on save data into another table.
    For the above requirement what the best way to implement in OAF.
    I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
    Thanks

    You can achieve this in many different ways, one is
    1. Create another VO based on the EO which is based on the dest table.
    2. At save, copy the contents of the source VO into the dest VO (see copy routine in dev guide).
    3. commiting the transaction will push the data into the dest table on which the dest VO is based.
    I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
    if by table you mean a DB table, then no, you can have a VO based on multiple EOs which will do DMLs accordingly.Thanks
    Tapash

  • How can I take an item from one image and move it to another image?

    How can I take an item from one image and add it to another image, and rotate it to fit?

    Carefully select the objects of interest in one image and then copy, scale and position them into the other image. Then touch up the composite.
    Have to Love Photoshop for Retouching Images!

Maybe you are looking for

  • How do I open a Word document in Photoshop Editor?

    Can't do it, It says it could not complete your request. It is not the right kind of document.

  • Yougou

    Can I use my Sony Bravia 55 inch (not 3D) 1080p with apple tv?

  • 'All Photographs' contains more photos than in folders

    All photographs collection contains more photos than in folders - (Using LR 4) There are about 6k more photos that are in my catalog (All Photographs) than what is showing up in my folders below.  All of my photos are located on an external hard driv

  • Partitioning Hard Drive

    I just placed a new hard drive into the second bay of my quad G5 and am thinking of partitioning it to hold the OS on one partition, the programs on the second partition, and my files on the third partition, would this be a good idea? Does it make a

  • Extract Filter

    I have gone from Photoshop CS to Photoshop CS4.  In Photoshop CS, there is an 'extract filter' which is brilliant at removing objects from one photo and pasting it to another.  I can't find this filter in Photoshop CS4.  Any idea where it is or what