Two things must occur for the web part to show up.
1. Assembly must be placed either in Global Assembly or in the /bin file of your wss/virtual directory. The default location is C:\Inetpub\wwwroot\wss\VirtualDirectories\80\bin (I'd recommend making a short cut to this, as you'll be using it often. The created web part assembly can be found under your project file, OR, your can right click on your project name and choose properties, then click on build. Select your 80/bin folder for the build location. It skips a step. a
2. Assembly must be registered as "Safe" in your web.config file. Remember your bin folder? Go up one from there and you'll find your web.config. The minimum reference for this is.
<SafeControl Assembly="MyAssemblyName" Namespace="MyNameSpace" TypeName="*" Safe="True" />
MyAssemblyName is the name on the actual DLL Name
MyNameSpace is the listed NameSpace on your class file
TypeName="*" means that EVERY webpart under this namespace is okay to use.
Shortcut to building MOST webparts
If you are like me, you are probably migrating a bunch of old content/forms, mini apps etc to a sharepoint environment.
Don't bother rebuilding your single page forms. All you need to do is convert them to a web control.
VS 2005/8
1. File, add, new - WebControl = this adds your basic structure, use code behind, its okay.
2. Go to old form, copy everything from BETWEEN the body tags, paste into new web control
3. do the same with your code, taking care to leave the partial class name alone. Ensure all hyper links are absolute, as the concept behind a web part says it can be dropped anywhere.
4. Save your new webcontrol to "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES" This is the default location for your primary 'hive'
5. Use this code for your new part. Starting from a new web part project
public class SimpleControlWebPart: System.Web.UI.WebControls.WebParts.WebPart
{
protected UserControl SimpleControl = null;
protected override void CreateChildControls()
{
this.SimpleControl = (UserControl)Page.LoadControl("/_controltemplates/SimpleControl.ascx");
this.Controls.Add(this.SimpleControl);
}
protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
{
this.EnsureChildControls();
this.SimpleControl.RenderControl(writer);
}
}
This assumes that SimpleControl is the name of your .ascs (web control) file. and that it has been saved to the control templates folder.
Deploy your web part.dll to your bin folder.
register as a safe control in web.config
go to your web part gallery and click new and look for your NAMESPACE.WEBPART, click it and hit populate gallery
edit any page, and drop your web part there. This is by far the easiest way to get rapid web parts up on sharepoint. Develop with normal .net features, and simply convert over to a web control and cruise on.
Gl, hf