1. Open Visual Studio 2005 and create a new Web Part project.
2. Add the following two using statements to the .cs file:
using System.ComponentModel;
using System.Net;
3. Add the following using statement to the AssemblyInfo.cs file:
using System.Security;
4. Add the following line at the end of the AssemblyInfo.cs file:
[assembly: AllowPartiallyTrustedCallers()]
5. Your Web Part should include a pre-assigned Guid. Add the ToolboxData and XmlRoot Namespace after the Guid and remember to replace ‘YourClassName’ where appropriate, like so:
[Guid("3854adbc-d5ac-47bd-885a-af46cc0f35d5"),
ToolboxData("<{0}:YourClassName runat=server></{0}:YourClassName>"),
XmlRoot(Namespace = "YourClassName")]
6. Your Web Part class should be inheriting from the System.Web.UI.WebControls.WebParts.WebPart class.
7. Add your code to the Render method, et al.
8. In Solution Explorer, rename the folder that is automatically created and named YourClassName to Solution and move the .cs file up one out of the Solution folder.
9. Add a manifest.xml file to the solution folder and place the following inside (remember to replace the instances of solution and class names, the solution id, and public key token with your own):
<Solution xmlns=”http://schemas.microsoft.com/sharepoint/” SolutionId=”ef5784a3-4970-459c-9397-57a95496f002“>
<Assemblies>
<Assembly Location=”YourSolutionName.dll” DeploymentTarget=”WebApplication“>
<SafeControls>
<SafeControl Assembly=”YourSolutionName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5” Namespace=”YourNamespace” TypeName=”*” Safe=”True” />
</SafeControls>
</Assembly>
</Assemblies>
<DwpFiles>
<DwpFile Location=”YourClassName.webpart“/>
</DwpFiles>
<CodeAccessSecurity>
<PolicyItem>
<PermissionSet class=”NamedPermissionSet” version=”1” Description=”Permission set for YourNamespace“>
<IPermission class=”AspNetHostingPermission” version=”1” Level=”Minimal” />
<IPermission class=”SecurityPermission” version=”1” Flags=”Execution” />
<IPermission class=”Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” version=”1” ObjectModel=”True” />
</PermissionSet>
<Assemblies>
<Assembly Name=”YourSolutionName“/>
</Assemblies>
</PolicyItem>
</CodeAccessSecurity>
</Solution>
10.Right-click on your project file and open the properties. Click on the SharePoint Solution tab to get your solution id. Copy and paste the solution id into the manifest.xml file, top line, SolutionId attribute.
11.Add another .xml file called YourClassName.webpart to your Solution folder (be sure to change the .xml extension to .webpart), and place the following inside:
<webParts>
<webPart xmlns=”http://schemas.microsoft.com/WebPart/v3“>
<metaData>
<type name=”YourNamespace.YourClassName,
YourSolutionName,
Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=9f4da00116c38ec5” />
<importErrorMessage>
YourSolutionName Cannot import YourWebPartName Web Part.
</importErrorMessage>
</metaData>
<data>
<properties>
<property name=”Title” type=”string“>A title for your Web Part</property>
<property name=”Description” type=”string“>A description for your Web Part</property>
<property name=”AllowClose” type=”bool“>FALSE</property>
</properties>
</data>
</webPart>
</webParts>
12.Add a text file called WSP.ddf to your Solution folder (be sure to change the .txt extension to .ddf), and place the following inside:
.Set CabinetNameTemplate=YourSolutionName.wsp ;Specifies the name of the output file
.Set DiskDirectoryTemplate=CDROM ;Indicates that all of the CAB goes into a single directory
.Set CompressionType=MSZIP ;Indicates that all of the files will be compressed into CAB files
.Set UniqueFiles=”ON” ;Indicates that all of the files referenced must be unique
.Set Cabinet=On ;Use cabinet files
.Set DiskDirectory1=. ;Use the current directory for the output CAB file
“C:\…Your Path…\Solution\manifest.xml”
“C:\ …Your Path…\bin\release\YourClassName.dll”
“C:\…Your Path…\Solution\YourClassName.webpart”
13.Compile the solution.
14.Create the cab file: From the directory in which you want the cab file saved, run the following command:
makecab /f “C:\…path to .ddf file…\WSP.ddf”
15.Open a command prompt from the server on which the Web Part is to be installed and change directory to the 12 hive bin directory:
cd “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\”
16.Run the following commands:
stsadm –o addsolution –filename “C:\…path to your file…\YourSolutionName.wsp”
stsadm –o deploysolution –name YourSolutionName.wsp –url [http://YourServerName OR –allcontenturls] –immediate –allowcaspolicies –force
17.Your .dll should be in the bin directory of the Web App you specified in the deploysolution command (or in all bin directories of all Web Apps if you used the –allcontenturls switch). It should NOT be in the GAC.
18.Visit the Solution Management page in Central Admin under the Operations tab. Your solution should be listed with a status of Deployed.
19.Visit one of your Front-end Web Servers to which the solution was deployed. Edit a page and click to add a Web Part to the page. Scroll down to the Miscellaneous category and you should fine your Web Part there.