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.
-
Poznámka
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.
Prerequisites
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.
Visual Studio 2010.
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 clicking New Site on the Site Actions tab.
In the site Create dialog box, click Blank Site.
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 click Create.
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 clicking New Site on the Site Actions tab and selecting Blank Site.
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 click Create.
Navigate back to the first subsite, http://system name/columntest1/SitePages/Home.aspx.
Click Site Settings on the Site Actions tab to display the Site Settings page.
Click the Site columns link in the Galleries section.
Click the Create button at the top of the Site Column Gallery page.
In the Column name box, enter Test Column. Keep the other default values and then click OK.
The column Test 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.
Důležité
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 SharePoint, click Site Settings on the Site Actions tab to display the Site Settings page.
Click the Save site as template link in the Site Actions section of the Site Settings page.
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, click the user solution gallery link to view the .wsp file.
To view the solutions gallery page later, click Site Actions on the Site Settings tab, click Go to top level site settings in the Site Collection Administration section, and then click the Solutions link in the Galleries section.
In the solutions gallery, click the ExampleSite link to display the File Download dialog box.
Click the Save button in the File Download dialog box and save the file on the system.
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, display the New Project dialog box by pointing to New on the File menu, and then click New Project.
Expand the SharePoint node under either Visual C# or Visual Basic, and then click 2010.
Click Import SharePoint Solution Package in the Templates pane, leave the name of the project as WspImportProject1, and then click OK.
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 click Next.
Poznámka
Clicking Finish on this page causes all available items in the .wsp file to be imported.
In the Select items to import box, clear all of the items in the list except for Test Column and then click Finish.
Because there are many items in the list, the easiest way to do this is to press CTRL + A to select all items in the list, press SPACE to clear the selection of all items, and then select 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, press F5 to deploy and run the .wsp import project.
Click Site Settings on the Site Actions tab to display the Site Settings page.
Click the Site columns link in the Galleries section.
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.
See Also
Concepts
Importing Items from an Existing SharePoint Site
Other Resources
Developing SharePoint Solutions
Creating Reusable Controls for Web Parts or Application Pages