| |
|
Creating list definition and WSP for a SharePoint list |
| |
In this article, you will see how a WSP for a SharePoint list is
created. I will not explain what is manifest.xml or cab.ddf,
just follow the steps in this article and create a WSP for your
SharePoint list in few simple steps. This is not a new topic and
have already been written about. Following are some popular
links that you may find useful:
Creating a SharePoint Solution Package (.WSP) in five steps
WSPBuilder Tool
Creating a Solution Package in Windows SharePoint Services 3.0
Creating
and Deploying SharePoint Solution Files
We will use "SharePoint Solution Generator" to create the WSP.
"SharePoint Solution Generator" is a free utility that comes
with the Visual Studio Extensions. You can download Visual
Studio 2008 extensions from the following link:
http://www.microsoft.com/downloads/details.aspx?familyid=7BF65B28-06E2-4E87-9BAD-086E32185E68&displaylang=en
You can download Visual Studio 2005 Extensions from the
following link:
http://www.microsoft.com/downloads/details.aspx?FamilyId=5D61409E-1FA3-48CF-8023-E8F38E709BA6&displaylang=en
In this article, I will use Visual Studio 2005 Extensions.
1. Start "SharePoint Solution Generator".

Figure 1: SharePoint Solution Generator
2. Select "List Definition" and click "Next".
3. Choose the site where the list is located. If you know the
site URL, select the second option "Specify a site url:" and
then enter the site URL and click "Next".
4. Select the list from the available lists and click "Next".
5. Enter a project name and select the location to save the
project. Click "Next".
6. Click "Finish" to start the list generation.
Figure 2: List generation in progress
7. Click the link "Click here to open the generated solution" to
open the project or click the "Exit" button to close the wizard.
8. Double click the .csproj file to open the project in Visual
Studio.
9. You need to add following three files in the project:
a. Instance.xml
b. Element.xml
c. Feature.xml
I have created a utility that creates these three files. I will
upload it somewhere very soon. Till then you need to create
these files manually.
| Feature.xml |
<?xml version="1.0" encoding="utf-8"?>
<Feature Id="06D1DF7A-3D3F-49b6-9388-74B8F26B50F2"
Title="MyList"
Description="MyList List Definition"
Version="1.0.0.0"
Scope="Web"
Hidden="FALSE"
DefaultResourceFile="MyList"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="Element.xml" />
<ElementFile Location="MyList\schema.xml" />
<ElementFile Location="MyList\AllItems.aspx" />
<ElementFile Location="MyList\DispForm.aspx" />
<ElementFile Location="MyList\EditForm.aspx" />
<ElementFile Location="MyList\NewForm.aspx" />
<ElementManifest Location="MyList\instance.xml"/>
</ElementManifests>
</Feature>
|
Change the "Feature Id". Use "Create GUID" tool in Visual Studio
to create the new GUID for the feature Id. Change the "Title"
and "Description". If you are copying and pasting above XML,
then replace "MyList" (wherever it is used) with your list's
name.

Figure 3: Create GUID Tool in Visual Studio
| Element.xml |
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ListTemplate
Name="MyList"
Type="10000"
BaseType="0"
OnQuickLaunch="TRUE"
SecurityBits="11"
Hidden="TRUE"
DisplayName="MyList"
Description="MyList List Definition"
Image=""/>
</Elements>
|
Change the name from "MyList" to your list's name. "Type" should
unique. You can use any number, condition is it should be
unique. Also, change "DisplayName" and "Description".
|
Instance.xml |
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ListInstance
FeatureId="06D1DF7A-3D3F-49b6-9388-74B8F26B50F2"
TemplateType="10000"
Title="MyList"
Description="MyList instance"
OnQuickLaunch="false"
Url="Lists/MyList">
</ListInstance>
</Elements>
|
Copy "FeatureId" from the "Feature.xml". "TemplateType" is the
unique number that you used in Element.xml also. This is the
template type and should always be unique. Change "Title",
"Description" and "Url".
If you want to show data in your list, it is this file
"Instance.xml" where you include your data. Use following
Instance.xml if you want to include data:
|
Instance.xml (with data) |
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ListInstance
FeatureId="06D1DF7A-3D3F-49b6-9388-74B8F26B50F2"
TemplateType="10000"
Title="MyList"
Description="MyList instance"
OnQuickLaunch="false"
Url="Lists/MyList">
<Data>
<Rows>
<Row>
<Field Name="YOUR FIELD NAME">My Value</Field>
<Field Name='ID'>1</Field>
</Row>
</Rows>
</Data>
</ListInstance>
</Elements>
|
Add all fields with their values inside "<Data><Rows><Row>" and
"</Row></Rows></Data>" tags.
10. If you are using latest version of Solution Generator, then
you may not face this issue but old version of Solution
Generator adds an extra line of code in the generated files,
which causes problems when the list is rendered in SharePoint.
So check your files and remove this redundant line if it is
there. For example, open "AllItems.aspx" and if it has the
following line (Remember, it will be a commented line) at the
top, remove it:
<!-- _filecategory="ListDefinition" _filetype="File"
_filename="AllItems.aspx" _uniqueid="c6101d3b-569f-4f42-ab91-ff241ebbb439"
-->
Save and close "AllItems.aspx".
11. Open "DispForm.aspx" and remove the following line from the
top and save the file:
<!-- _filecategory="ListDefinition" _filetype="File"
_filename="DispForm.aspx" _uniqueid="bb83bef0-619f-4742-9314-7ec4efcb4631"
-->
12. Open "EditForm.aspx" and remove the following line from the
top and save the file:
<!-- _filecategory="ListDefinition" _filetype="File"
_filename="EditForm.aspx" _uniqueid="ef8f4a9d-7109-42bb-a966-fe8e9b13f63a"
-->
13. Open "NewForm.aspx" file and remove following line from the
top and save the file:
<!-- _filecategory="ListDefinition" _filetype="File"
_filename="NewForm.aspx" _uniqueid="a4917934-bc03-4c64-99c6-f2d68cebb087"
-->
14. Open "Schema.xml" file and remove following line (It will be
the second line):
<!-- _filecategory="ListDefinition" _filetype="Schema"
_filename="schema.xml" _uniqueid="96557fd3-f461-464a-9c7a-fb09f8598cea"
-->
Change the value in the "Type" attribute of the <List> tag. This
will be the first line in the code. Change the value to the
unique template Id that you used in Element.xml and
Instance.xml. The line will look like as following after the
change:
< List
Title="Announcements"
Description="Use
the Announcements list to post messages on the home page of your
site."
Direction="0"
BaseType="0"
Url="Lists/Announcements"
FolderCreation="FALSE"
Version="0"
Type="10000"
xmlns="http://schemas.microsoft.com/sharepoint/">
Save the file.
15. Add a new folder called "Solution" in the project. Add
two files "cab.ddf" and "manifest.xml" in the folder. Add a
folder called "Package" in the "Solution" folder and add a file
"Setup.bat" in it.

Figure 4: Folder structure
16. Here is manifest.xml:
|
Manifest.xml |
< Solution
SolutionId="53571E0D-0240-427e-AB0E-2412D0729C5C"
xmlns="http://schemas.microsoft.com/sharepoint/"
>
< FeatureManifests>
< FeatureManifest
Location="MyList\feature.xml"
/>
</ FeatureManifests>
</ Solution>
|
Create new GUID for the "SolutionId".
17. cab.ddf should look like the following:
| cab.ddf |
; ** MyList.wsp **
.OPTION EXPLICIT ; Generate errors
.Set CabinetNameTemplate=MyList.wsp
.set DiskDirectoryTemplate=CDROM ; All cabinets go in a
single directory
.Set CompressionType=MSZIP ; ** All files are compressed
in cabinet files
.Set UniqueFiles="ON"
.Set Cabinet=on
.Set DiskDirectory1=Solution\Package
Solution\manifest.xml manifest.xml
MyList\Feature.xml MyList\Feature.xml
MyList\Element.xml MyList\Element.xml
MyList\instance.xml MyList\MyList\instance.xml
MyList\AllItems.aspx MyList\MyList\AllItems.aspx
MyList\DispForm.aspx MyList\MyList\DispForm.aspx
MyList\EditForm.aspx MyList\MyList\EditForm.aspx
MyList\NewForm.aspx MyList\MyList\NewForm.aspx
MyList\schema.xml MyList\MyList\schema.xml
bin\Debug\MyList.dll MyList.dll
; ** end **
|
18. Copy following code and paste in the "setup.bat":
| setup.bat |
@rem======================================================================
@rem
@rem setup.bat
@rem
@rem======================================================================
@echo off
setlocal
pushd .
goto LInitialize
@rem----------------------------------------------------------------------
@rem LInitialize
@rem----------------------------------------------------------------------
:LInitialize
set SPAdminTool=%CommonProgramFiles%\Microsoft
Shared\web server extensions\12\BIN\stsadm.exe
set Install=
set Uninstall=
set PackageFile=%~dp0MyList.wsp
set PackageName=MyList.wsp
set DefaultWebUrl=http://myserver/
set DefaultSiteUrl=http://myserver/
set TargetWebUrl=
set TargetSiteUrl=
goto LParseArgs
@rem----------------------------------------------------------------------
@rem LParseArgs
@rem----------------------------------------------------------------------
:LParseArgs
@rem --- help ---
if "%1" == "/?" goto LHelp
if "%1" == "-?" goto LHelp
if "%1" == "/h" goto LHelp
if "%1" == "-h" goto LHelp
if "%1" == "/help" goto LHelp
if "%1" == "-help" goto LHelp
@rem --- Fix execute task ---
if "%1" == "/i" (set Install=1) & shift & goto
LParseArgs
if "%1" == "-i" (set Install=1) & shift & goto
LParseArgs
if "%1" == "/install" (set Install=1) & shift & goto
LParseArgs
if "%1" == "-install" (set Install=1) & shift & goto
LParseArgs
if "%1" == "/u" (set Uninstall=1) & shift & goto
LParseArgs
if "%1" == "-u" (set Uninstall=1) & shift & goto
LParseArgs
if "%1" == "/uninstall" (set Uninstall=1) & shift & goto
LParseArgs
if "%1" == "-uninstall" (set Uninstall=1) & shift & goto
LParseArgs
@rem --- Fix url ---
if "%1" == "/weburl" (set TargetWebUrl=%2) & shift &
shift & goto LParseArgs
if "%1" == "-weburl" (set TargetWebUrl=%2) & shift &
shift & goto LParseArgs
if "%1" == "/siteurl" (set TargetSiteUrl=%2) & shift &
shift & goto LParseArgs
if "%1" == "-siteurl" (set TargetSiteUrl=%2) & shift &
shift & goto LParseArgs
@rem --- Check invalid arguments ---
if not "%1" == "" (
echo Invalid argument.
goto LHelp
)
@rem --- Check arguments ---
if "%Install%" == "1" (
if "%Uninstall%" == "1" (
goto LHelp
)
)
if "%Install%" == "" (
if "%Uninstall%" == "" (
set Install=1
)
)
if "%TargetSiteUrl%" == "" (
if "%TargetWebUrl%" == "" (
set TargetWebUrl=%DefaultWebUrl%
set TargetSiteUrl=%DefaultSiteUrl%
)
if not "%TargetWebUrl%" == "" (
set TargetSiteUrl=%TargetWebUrl%
echo Setting TargetSiteUrl to be %TargetWebUrl%
)
)
if "%TargetWebUrl%" == "" (
set TargetWebUrl=%TargetSiteUrl%
echo Setting TargetWebUrl to be %TargetSiteUrl%
)
goto LMain
@rem----------------------------------------------------------------------
@rem LHelp
@rem----------------------------------------------------------------------
:LHelp
echo Usage:
echo setup.bat [/install or /uninstall][/weburl ^<url^>][/siteurl
^<url^>]
echo [/help]
echo.
echo Options:
echo /install or /uninstall
echo Install specified Solution package (.wsp) to the
SharePoint server
echo or uninstall specified Solution from the SharePoint
server.
echo Default value: install
echo /weburl
echo Specify a web url of the SharePoint server.
echo Default value: %DefaultWebUrl%
echo /siteurl
echo Specify a site url of the SharePoint server.
echo Default value: %DefaultSiteUrl%
echo /help
echo Show this information.
echo.
goto LTerminate
@rem----------------------------------------------------------------------
@rem LMain
@rem----------------------------------------------------------------------
:LMain
if "%Install%" == "1" (
call :LDeploy
)
if "%Uninstall%" == "1" (
call :LRetract
)
goto LTerminate
@rem----------------------------------------------------------------------
@rem LDeploy
@rem----------------------------------------------------------------------
:LDeploy
echo Adding solution %PackageName% to the SharePoint ...
"%SPAdminTool%" -o addsolution -filename "%PackageFile%"
echo Deploying solution %PackageName% ...
"%SPAdminTool%" -o deploysolution -name "%PackageName%"
-local -allowGacDeployment
echo Activating feature MyList ...
"%SPAdminTool%" -o activatefeature -id
06D1DF7A-3D3F-49b6-9388-74B8F26B50F2 -url %TargetWebUrl%
goto :EOF
@rem----------------------------------------------------------------------
@rem LRetract
@rem----------------------------------------------------------------------
:LRetract
echo Deactivating feature MyList ...
"%SPAdminTool%" -o deactivatefeature -id
06D1DF7A-3D3F-49b6-9388-74B8F26B50F2 -url %TargetWebUrl%
echo Uninstalling feature MyList ...
"%SPAdminTool%" -o uninstallfeature -id
06D1DF7A-3D3F-49b6-9388-74B8F26B50F2 -force
echo Retracting solution %PackageName% ...
"%SPAdminTool%" -o retractsolution -name "%PackageName%"
-local
echo Deleting solution %PackageName% from SharePoint ...
"%SPAdminTool%" -o deletesolution -name "%PackageName%"
goto :EOF
@rem----------------------------------------------------------------------
@rem LTerminate
@rem----------------------------------------------------------------------
:LTerminate
set UserInput=
set /P UserInput=Hit enter key to quit.
set SPAdminTool=
set PackageFile=
set PackageName=
set Install=
set Uninstall=
set TargetSiteUrl=
set TargetWebUrl=
set UserInput=
popd
endlocal
|
Use Ctrl-H to replace all instances of "MyList" with your list's
name. Also, don't forget to change the feature ID.
ActivateFeature, DeactivateFeature and UninstallFeature commands
should have your list's feature ID.
19. Compile the project.
20. Open command prompt and go to the project folder and run
following command to create the WSP file:
makecab /f solution/cab.ddf
For example, If your project location is "C:\Projects\MyList",
go to this folder and run the above command from the command
prompt.
It will create a WSP for your list definition that you will be
able to use to install or uninstall the list on other servers.
Download Visual Studio project
(Project has all files needed to create the WSP)
|
|