.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Squadron for SharePoint 2010 - Copy Items

Posted By:Jean Paul       Posted Date: November 30, 2013    Points: 200    Category: SharePoint    URL: http://www.dotnetspark.com  

In this article we have explored the Copy Items functionality of Squadron. You are free to download the tool and start using it. As always I am listening for new & new features integration into Squadron.
 

In this article we can explore new feature integration to our Squadron Tool for SharePoint 2010.

clip_image001

Copy Items

The Copy Items functionality is simple as the name implies:

ยท It copies list items from source server list to destination server list

It helps us in the following ways:

1. Quick Creation of Lists from server to another

2. Duplication of Items if the lists are same

3. Multiple List copying

We can use the tool to copy multiple lists across sites..

clip_image003

clip_image005

Squadron 2010 is a Utility Add in Application for SharePoint 2010. It is available for download from:

http://squadron2010.codeplex.com/

The method performs the following:

1. Accepts a Source List Item and Destination List

2. Creates a New List Item inside Destination List

3. Iterates over each Field of the Source Item and copies the property to Destination Item

4. Discards field names of 'Attachments'

5. Updates the list item on the end of method

Start using the Tool

You can download the tool from above location.

Step 1: Execute the Tool

You will get the following screen on execution.

clip_image007

Step 2: Click Copy Items

Click on the Copy Items item from the left pane and you will see the following add-in.

clip_image009

Step 3: Source Server Connect

As the screen implies, you have to do the following steps of actions:

Step 1: Source Server Connect In this step input the URL of the Source Server. You can enter the user name if needed higher permissions. (By default it is SHAREPOINT\system)

For the time being enter your SharePoint site url here:

http://localhost/

Then click the Refresh button. You will get the Lists loaded in the Step 2 box as shown below.

clip_image011

Step 4: Source List Select

Check those lists which you wish to copy. For the time being I have checked 2 lists.

clip_image013

Please note that the Number of List Items are shown within Parenthesis. 

Step 5: Destination Server Connect

In this step input the URL of the Destination Server. You can enter the user name if needed higher permissions. (By default it is SHAREPOINT\system)

You can choose the same Site URL, if you wish to create duplicate items.

You can choose a different Site URL, to create the list and copy the items. Please note that the new List created will be having same List Template & Quick Launch property as the Source List.

For the time being I have created another sub site inside the local host. My URL would be:

http://localhost/newsite

After entering the URL click the Refresh button to the right.

clip_image015

You will see the Step4: Finalize section populated with the Source & Destination list names.

Please note that if there is no destination list, a new list will be created & items will be copied.

If there is a destination list with incompatible structure, the copying for the particular list won't be performed.

Step 5: Copy Items

This step performs the COPY operation. You can see the progress through the progress bar and log message box. Click on the COPY button to start copying.

clip_image017

Within a few seconds the copy operation will be completed and you will get the STATUS BARS updated as shown above. The log box will be displaying the copy operation details.

clip_image005[1]

For reference purpose I have attached the source code for Copy Items along with this article. 

Step 6: Verifying the Data

Now we can go back to the new SharePoint site to verify the Lists & Data. You can see that there are 2 new Lists created & items are copied.

Following is the data for Contacts list in the destination site.

clip_image019

Following is the data for Tasks 1 list in the destination site.

clip_image021

clip_image005[2]

The current functionality only allows List items copying. In future Library items copying will be included.

Underlying Code

The underlying code that performs the Copy Items functionality is following method:

 

  private void CopyItem(SPListItem item, SPList destList)
  {
    SPListItem newItem = destList.Items.Add();

    for (int i = 0; i < item.Fields.Count; i++)
        if ((!newItem.Fields[i].ReadOnlyField) 
&& (newItem.Fields[i].InternalName != "Attachments"))
            newItem[newItem.Fields[i].InternalName] = item[newItem.Fields[i].InternalName];

    newItem.Update();
  }

In case of the Destination List is not existing, we need to create a new List with the same structure. Following is the code that performs the same.

 

private SPList CreateList(SPWeb sourceWeb, SPWeb destinationWeb, string stitle, string dTitle)
  {
    SPList slist = sourceWeb.Lists[stitle];
    Guid dguid = destinationWeb.Lists.Add(dTitle, slist.Description, slist.BaseTemplate);

    SPList dlist = destinationWeb.Lists[dguid];
    dlist.OnQuickLaunch = slist.OnQuickLaunch;
    dlist.Update();

    return dlist;
  }

Copying between incompatible list structures are not allowed. The check is performed by the following code:

 

private bool IsStructureValid()
  {
    SPList sourceList = SourceWeb.Lists[SourceListName];
    SPList destList = DestinationWeb.Lists[DestinationListName];

    for (int i = 0; i < sourceList.Fields.Count; i++)
    {
        string fieldName = sourceList.Fields[i].Title;

        if (!destList.Fields.Cast<SPField>().Any(f => f.Title == fieldName))
            return false;

        if (destList.Fields[fieldName].Type != sourceList.Fields[i].Type)
            return false;
    }

    return true;
  }

This concludes our article on Copy Items add-in for Squadron. I hope this add-in will be useful.

References

http://squadron2010.codeplex.com/

http://tinyurl.com/bh4x9h3

Summary

In this article we have explored the Copy Items functionality of Squadron. You are free to download the tool and start using it. As always I am listening for new & new features integration into Squadron.


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend