Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 211721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:07:15+00:00 2026-05-11T18:07:15+00:00

I have items in a list in a SharePoint 2003 site that I need

  • 0

I have items in a list in a SharePoint 2003 site that I need to add to an existing list in a 2007 site. The items have attachments.

How can this be accomplished using PowerShell or C#?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:07:15+00:00Added an answer on May 11, 2026 at 6:07 pm

    I ended up using a C# program in conjunction with the SharePoint web services to accomplish this. I also used the extension methods (GetXElement, GetXmlNode) on Eric White’s blog here to convert between XMLNodes and XElements which made the XML from SharePoint easier to work with.

    Below is a template for most of the code needed to transfer list data, including attachments, from one SharePoint List (either 2003 or 2007) to another one:

    1) This is the code moves attachments after a new item has been added to the target list.

    // Adds attachments from a list item in one SharePoint server to a list item in another SharePoint server.
    //   addResults is the return value from a lists.UpdateListItems call.
    private void AddAttachments(XElement addResults, XElement listItem)
    {
        XElement itemElements = _listsService2003.GetAttachmentCollection(_listNameGuid, GetListItemIDString(listItem)).GetXElement();
    
        XNamespace s = "http://schemas.microsoft.com/sharepoint/soap/";
    
        var items = from i in itemElements.Elements(s + "Attachment")
                    select new { File = i.Value };
    
        WebClient Client = new WebClient();
        Client.Credentials = new NetworkCredential("user", "password", "domain");
    
        // Pull each attachment file from old site list and upload it to the new site list.
        foreach (var item in items)
        {
    
            byte[] data = Client.DownloadData(item.File);
            string fileName = Path.GetFileName(item.File);
            string id = GetID(addResults);
            _listsService2007.AddAttachment(_newListNameGuid, id, fileName, data);
        }
    }
    

    2) Code that iterates through the old SharePoint List and populates the new one.

        private void TransferListItems()
        {
    
            XElement listItems = _listsService2003.GetListItems(_listNameGuid, _viewNameGuid, null, null, "", null).GetXElement();
    
            XNamespace z = "#RowsetSchema";
            foreach (XElement listItem in listItems.Descendants(z + "row"))
            {
                AddNewListItem(listItem);
            }
        }
    
        private void AddNewListItem(XElement listItem)
        {
            // SharePoint XML for adding new list item.
            XElement newItem = new XElement("Batch",
                new XAttribute("OnError", "Return"),
                new XAttribute("ListVersion", "1"),
                new XElement("Method",
                    new XAttribute("ID", "1"),
                    new XAttribute("Cmd", "New")));
    
            // Populate fields from old list to new list mapping different field names as necessary.
            PopulateFields(newItem, listItem);
    
            XElement addResults = _listsService2007.UpdateListItems(_newListNameGuid, newItem.GetXmlNode()).GetXElement();
    
            // Address attachements.
            if (HasAttachments(listItem))
            {
                AddAttachments(addResults, listItem);
            }
        }
    
        private static bool HasAttachments(XElement listItem)
        {
            XAttribute attachments = listItem.Attribute("ows_Attachments");
    
            if (System.Convert.ToInt32(attachments.Value) != 0)
                return true;
    
            return false;
        }
    

    3) Miscellaneous support code for this sample.

        using System.Collections.Generic;
        using System.Linq;
        using System.Windows.Forms;
        using System.Xml.Linq;
        using System.Net;
        using System.IO;
    
        // This method uses an map List<FieldMap> created from an XML file to map fields in the
        // 2003 SharePoint list to the new 2007 SharePoint list.
        private object PopulateFields(XElement batchItem, XElement listItem)
        {
            foreach (FieldMap mapItem in FieldMaps)
            {
                if (listItem.Attribute(mapItem.OldField) != null)
                {
                    batchItem.Element("Method").Add(new XElement("Field",
                        new XAttribute("Name", mapItem.NewField),
                            listItem.Attribute(mapItem.OldField).Value));
                }
            }
    
            return listItem;
        }
    
        private static string GetID(XElement elem)
        {
            XNamespace z = "#RowsetSchema";
    
            XElement temp = elem.Descendants(z + "row").First();
    
            return temp.Attribute("ows_ID").Value;
        }
    
        private static string GetListItemIDString(XElement listItem)
        {
            XAttribute field = listItem.Attribute("ows_ID");
    
            return field.Value;
        }
    
        private void SetupServices()
        {
            _listsService2003 = new SPLists2003.Lists();
    
            _listsService2003.Url = "http://oldsite/_vti_bin/Lists.asmx";
            _listsService2003.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
    
            _listsService2007 = new SPLists2007.Lists();
    
            _listsService2007.Url = "http://newsite/_vti_bin/Lists.asmx";
            _listsService2007.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
    
        }
    
        private string _listNameGuid = "SomeGuid";      // Unique ID for the old SharePoint List.
        private string _viewNameGuid = "SomeGuid";      // Unique ID for the old SharePoint View that has all the fields needed.
        private string _newListNameGuid = "SomeGuid";   // Unique ID for the new SharePoint List (target).
    
        private SPLists2003.Lists _listsService2003;    // WebService reference for the old SharePoint site (2003 or 2007 is fine).
        private SPLists2007.Lists _listsService2007;    // WebService reference for the new SharePoint site.
    
        private List<FieldMap> FieldMaps;   // Used to map the old list to the new list. Populated with a support function on startup.
    
        class FieldMap
        {
            public string OldField { get; set; }
            public string OldType { get; set; }
            public string NewField { get; set; }
            public string NewType { get; set; }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list in SharePoint that has versioning turned on. This list contains
I have a sharepoint list, and want to get all the items of that
I have a list on SharePoint with several hundred items in it. I also
I have a list of class items List<MyClass> I have a seperate object that
Can someone suggest what I am doing wrong? Basically I have a List Items,
I have a list box control that contains enough items to list them with
I have a set of list items in unordered lists that I bind the
I've build a custom SharePoint list that programatically adjusts permissions per list item. This
I have some event handlers which are tracking list items in my SharePoint lists.
I have a custom built web service that is built to simply add items

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.