Walkthrough: Import Items from an Existing SharePoint Site
This walkthrough demonstrates how to import items from an existing SharePoint site into a Visual Studio SharePoint project.
This walkthrough demonstrates the following tasks:
Customizing a SharePoint site by adding a custom site column (also known as a field.
Exporting a SharePoint site to a .wsp file.
Importing the .wsp file into Visual Studio SharePoint by using the .wsp Import project.
Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.
You need the following components to complete this walkthrough:
Supported editions of Microsoft Windows and SharePoint. For more information, see Requirements for Developing SharePoint Solutions.
Customizing a SharePoint Site
For this example, you will create and customize a SharePoint subsite by adding a new site column to it and by creating another subsite for use later. Later, you will export the first subsite to a .wsp file and then import the custom site column into the second subsite by using the .wsp Import project.
To create and customize a SharePoint site
Open a SharePoint site using a Web browser, such as http://system name/SitePages/Home.aspx.
Create a subsite off of the main SharePoint site by opening the Site Actions menu and then choosing New Site.
In the site’s Create dialog box, choose the Blank Site type.
In the Title box, enter Site Column Test 1; in the URL name box, enter columntest1; leave the other settings at their default values; and then choose the Create button.
After the site is created, navigate in the browser back to the main site, http://system name/SitePages/Home.aspx.
Again, create a blank subsite off of the main SharePoint site by opening the Site Actions menu, choosing New Site, and then choosing the Blank Site type.
In the Title box, enter Site Column Test 2; in the URL name box, enter columntest2; leave the other settings at their default values; and then choose the Create button.
Navigate back to the first subsite, http://SystemName/columntest1/default.aspx.
On the Site Actions menu, choose Site Settings to display the Site Settings page.
In the Galleries section, choose the Site columns link.
At the top of the Site Column Gallery page, choose the Create button.
In the Column name box, enter Test Column, keep the other default values, and then choose the OK button.
The Test Column column appears under the Custom Columns heading in the Site Column Gallery.
Exporting the SharePoint Site
Next, obtain a SharePoint setup (.wsp) file that contains the SharePoint items and elements that you want to import into your Visual Studio SharePoint project. If you do not already have a .wsp file, then you must create one from an existing SharePoint site. For this example, you will export the default SharePoint site into a .wsp file.
If you receive a runtime error performing the following procedure, you have to perform the procedure on a system that has access to the SharePoint site.
To export an existing SharePoint site
In the SharePoint site, choose Site Settings on the Site Actions tab to display the Site Settings page.
In the Site Actions section of the Site Settings page, choose the Save site as template link.
In the File name box, enter ExampleSite, and in the Template name box, enter Example Site.
For this example, leave the Include Content check box clear.
If you select this box, Visual Studio saves all lists and document libraries, and their contents, to the .wsp file. Although this is useful in some circumstances, it is not required for this example.
When the operation completes successfully, choose the solution gallery link to view the .wsp file.
To view the solutions gallery page later, open the Site Actions menu, choose Site Settings, choose the Go to top level site settings link in the Site Collection Administration section, and then choose the Solutions link in the Galleries section.
In the solutions gallery, choose the ExampleSite link.
In the File Download dialog box, choose the Save button to save the file on your local system, by default, in your Downloads folder.
Importing the .wsp File
Now that you have a .wsp file that contains an item that you want to reuse (the custom site column Test Column), import the .wsp file to access it.
To import a .wsp file
In Visual Studio, on the menu bar, choose File, New, Project to display the New Project dialog box. If your IDE is set to use Visual Basic development settings, on the menu bar, choose File, New Project.
Expand the SharePoint node under either Visual C# or Visual Basic, and then choose the 2010 node.
Choose the Import SharePoint 2010 Solution Package template in the Templates pane, leave the name of the project as WspImportProject1, and then choose the OK button.
The SharePoint Customization Wizard appears.
On the Specify the site and security level for debugging page, enter the URL for the second SharePoint subsite that you created earlier. You will add the new custom Field item, http://system name/columntest2, to that subsite.
In the What is the trust level for this SharePoint solution? section, leave the selection as Deploy as a sandboxed solution.
In the Specify the new project source page, browse to the location on the system where you saved the .wsp file previously and then choose the Next button.
If you choose the Finish button on this page, all available items in the .wsp file will be imported.
In the Select items to import box, clear all of the check boxes in the list except for Test Column, and then choose the Finish button.
Because the list contains many items, you can choose the Ctrl + A keys to choose all items in the list, choose the Spacebar key to clear all of the check boxes, and then select only the check box next to the Test Column item.
After the import operation is finished, a new project named WspImportProject1 is created that contains a folder named Fields. In this folder is the custom site column Test Column and its definition file Elements.xml.
Deploying the Project
Finally, deploy WspImportProject1 to the second SharePoint subsite that you created earlier to view the custom site column.
To deploy the project
In Visual Studio, choose the F5 key to deploy and run the .wsp import project.
On the SharePoint site, open the Site Actions menu, and then choose Site Settings to display the Site Settings page.
In the Galleries section, choose the Site columns link.
Scroll down to the Custom Columns section.
Notice that the custom site column that you imported from the first SharePoint site appears in the list.