1

I am trying to copy items to a list but it sits on a different farm in the same domain. Please point me in the right direction. Some of the code is as below:

string _destination = null;
        string _url = null;

            string FieldID = sourceItem["Field 1"].ToString();
            string EmpInitials = "";

            foreach (SPListItem itemL in listItems)
            {
                if (itemL["Destination List"].ToString().ToLower() == _employer.ToLower())
                {
                    _url = itemL["Site Url"].ToString();
                }
            }

            using (SPSite DestinationSite = new SPSite(_url)) 
            {
                SPWeb DestinationWeb = DestinationSite.OpenWeb();
                SPList DestinationList = DestinationWeb.Lists.TryGetList(Destination);

                if (DestinationList != null)
                {
                    SPListItemCollection dListItems = DestinationList.Items;
                    SPListItem newItem = dListItems.Add();
                    newItem["Field 1"] = ClaimNumber;
                    newItem.Update();
                }
            }
3
  • Do you know what part of your code that does not work?
    – Pantani
    Mar 5, 2014 at 10:48
  • The code works fine if the site is on the same web application but if it is on another farm I get the error : System.IO.FileNotFoundException: The Web application at sitename/lists/dest could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.
    – Chester238
    Mar 5, 2014 at 11:53
  • You could try accessing the list on the other farm by using WCF Data Services. Please refer to the following link Accessing SharePoint 2010 Lists by Using WCF Data Services
    – Pantani
    Mar 5, 2014 at 12:52

3 Answers 3

2

You are using server side API. It can only be executed on a SharePoint Server and can only access current farm.

If you want to access sites in another farm you need to use CSOM or web services.

0

Here's a suggestion:

SharePoint 2013: PowerShell to copy or update list items across SharePoint sites and farms

http://social.technet.microsoft.com/wiki/contents/articles/25125.sharepoint-2013-powershell-to-copy-or-update-list-items-across-sharepoint-sites-and-farms.aspx?wa=wsignin1.0

I believe it supports 2010 to 2013, 2010 to 2010, and 2013 to 2013.

0

If that doesn't tickle your fancy you can try it via web services:

How to: Update List Items

http://msdn.microsoft.com/en-us/library/ms440289.aspx

Lists.UpdateListItems Method

http://msdn.microsoft.com/en-us/library/lists.lists.updatelistitems.aspx

I used the snippets from the above links to add the process to a WCF service that was on the same WFE as the remote sharepoint server (different domain too) and made a call to that web service from a web part that was on the local sharepoint server. This allowed me to insert or update list items on both servers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.