In this simple tutorial, you will see how to create a simple custom Web Part with Microsoft Visual Studio 2005. In this tutorial, I will create a simple web part called "Hello Sharepoint-Girl".
1) Launch Visual Studio 2005.
2) Select File --> New --> Project.
3) Select C# under Project Type.
4) Select Class Library under Visual Studio Installed templates.
5) Type HelloSharepointGirl in the Name textbox.
6) Select a location in your hard drive.
7) Click on the OK Button to create the HelloSharepointGirl web part.
8) Rename the Class1.cs source file to HelloSharepointGirl.cs
9) Right-click on the Reference foler in the Solution Explorer and the select Add Reference...
10) In the .NET tab, select System.Web and then click on the OK button to add the reference.
11) Replace the code in the HelloSharepointGirl.cs file with the following code.
12) In the Solution Explorer, right-click on the Properties folder and then select Open.
13) Select the Signing tab.
14) Check the Sign the Assembly checkbox.
15) Select New in the Choose a strong name file..
16) Type a desired name in the key file name.
17) Click on the OK button. Now, Visual Studio will sign your assembly with Strong Name whenever you compile the project.
18) Click on Build --> Build Solution.
19) If no error returned by the compiler, you can proceed to copy the DLL to the bin directory of your WSS site (C:\Inetpub\wwwroot\wss\VirtualDirectories\80\bin OR other directories depending on your setup).
20) Modify the Web.Config file for the WSS site to declare the custom web part as a safe control by adding the following code within the <SafeControls> tag.
<SafeControl Assembly="HelloSharepointGirl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=162a44794eb4da93" Namespace="HelloSharepointGirl" TypeName="*" Safe="True" AllowRemoteDesigner="True" />
Note:
Please do not copy the PublicKeyToken in this example. You should have a different PublicKeyToken than the one shown in the example. You can get the PublicKeyToken with the sn.exe (strong name utility). Get PublicKeyToken with sn.exe.
21) Open you WSS site and then click on Site Actions --> Site Settings.
22) Click on the Web Parts link under the Galleries section.
23) Click on the New button.
24) Check the HelloSharepointGirl web part to select it and then click on the Populate Gallery button.
25) Now, you can add the HelloSharepointGirl web part to your site.
WSS Web Part Tutorial
Subscribe to:
Post Comments (Atom)
12 comments:
Thanks..
but when i press Populate Gallery button a new webpart was created and when i clicked on that i got an error page saying --
Assemblies that implement ASP.NET Web Parts and are installed into a partially trusted location, such as the bin directory, must be compiled with the AllowPartiallyTrustedCallersAttribute set for import to succeed
please help !!
Hey i got the solution :) --
Add the code statements using System.Security; and [assembly: AllowPartiallyTrustedCallers] to your AssemblyInfo.cs file.
Every thing goes fine but when I am trying to add this new webpart it is not in the list of Web Part Gallery.
I dont know what to do?
I have the same problem like Sohail Raza..Someone can help us?
check that the PublicKeyToken=162a44794eb4da93" is the same
the public key may be different, check in the GAC or use Red Gate's Reflector
Nice !!!!!!!!
Create Custom SharePoint WebParts, it is simple.
Try this too,
Custom SharePoint
WebParts
Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!
AllwPartiallyTrusted error
Change:TypeName="HelloSharepointGirl"
Thanks a lot.. you saved my time !!!
In step 20, please change the PublicKeyToken accordingly.You should have your own PublicTokenKey. You cannot use 162a44794eb4da93 as your token key.
if you're doing this tutorial in VB, rather than C#, you have to be careful about the namespace. Either: 1 - don't enclose the class in a namespace, 2 - empty the root namespace in the myproject/application settings, or 3 - in your safecontrol tag use HelloSharepointGirl.HelloSharepointGirl as the namespace.
Post a Comment