A SharePoint Content Type project allows the user to create a content type based on the built-in SharePoint content types. But what about situations where one would want to re-use a built-in field(s) in SharePoint? One way to do this is to use the "Import SharePoint Solution Package" project. This article provides the simple step-by-step procedures on how to achieve this.
To begin, let's first create a subsite. Imagine this as the site you want to copy the field from. This may or may not be on the same development machine that you're using.
To create a subsite in SharePoint:
The “SourceSite” subsite is now created. Let's now use SharePoint's "Save site as template" feature to export the entire subsite to a .wsp file.
To export a subsite to a .wsp file:
We're now ready to import the field into Visual Studio.
To import a field into Visual Studio:
A project will be created that contains the Fields project item. Double-clicking on this project item will show the contents of its Elements.xml:
Let's now create a content type that will use these fields that we just imported.
To add a Content Type project item:
We now modify the content type to reference the imported fields.
To reference the fields in the content type:
Note: o Make sure you change the Field tags to FieldRef. o Only the ID, Name, and DisplayName attributes are needed.
We are now ready to debug and deploy the content type and fields.
To debug the content type and fields:
You'll see the Address, City, State/Province and Zip/Postal Code fields in the columns section.The next step is to create a List Definition and List Instance based on the Content Type.
To create a List Definition and List Instance based on the Content Type:
A List Definition and List Instance project item are added to the project.
To debug the List Definition and List Instance:
You'll notice the Address, City, State, and Zip fields are not displayed in the list. To display them, follow these steps:
To display certain fields in the list:
That's it! You've now inherited fields, referenced them in a content type, created a list definition based on the content type, and displayed the fields in the list instance. Hope this helps! :)
Ian Ching
ummmm ummmm smoochhhhhhhhhhhhh Thanks u r the best love this approach....my project budget is going to be rediced in half..