Click here to Skip to main content
15,894,539 members
Articles / Programming Languages / C#

How to Create Installer (.cab) for web part?

Rate me:
Please Sign up or sign in to vote.
3.36/5 (7 votes)
30 Jun 20052 min read 61.3K   161   21  
A sample project (Hello world webpart and installer project) and walk through for creating an installer for web part that will install the webpart on the share point portal site.
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;

namespace WpSampleHelloWorld
{
	/// <summary>
	/// Description for HelloWorld.
	/// </summary>
	[DefaultProperty("Text"),
		ToolboxData("<{0}:HelloWorld runat=server></{0}:HelloWorld>"),
		XmlRoot(Namespace="WpSampleHelloWorld")]
	public class HelloWorld : Microsoft.SharePoint.WebPartPages.WebPart
	{
		private const string defaultText = "";

		private string text = defaultText;

		[Browsable(true),
			Category("Miscellaneous"),
			DefaultValue(defaultText),
			WebPartStorage(Storage.Personal),
			FriendlyName("Text"),
			Description("Text Property")]
		public string Text
		{
			get
			{
				return text;
			}

			set
			{
				text = value;
			}
		}
	
		/// <summary>
		///	This method gets the custom tool parts for this Web Part by overriding the
		///	GetToolParts method of the WebPart base class. You must implement
		///	custom tool parts in a separate class that derives from 
		///	Microsoft.SharePoint.WebPartPages.ToolPart. 
		///	</summary>
		///<returns>An array of references to ToolPart objects.</returns>
//		public override ToolPart[] GetToolParts()
//		{
//			ToolPart[] toolparts = new ToolPart[2];
//			WebPartToolPart wptp = new WebPartToolPart();
//			CustomPropertyToolPart custom = new CustomPropertyToolPart();
//			toolparts[0] = wptp;
//			toolparts[1] = custom;
//			return toolparts;
//		}
	
		/// <summary>
		/// Render this Web Part to the output parameter specified.
		/// </summary>
		/// <param name="output"> The HTML writer to write out to </param>
		protected override void RenderWebPart(HtmlTextWriter output)
		{
			output.Write("Hello World");
			output.Write(SPEncode.HtmlEncode(Text));
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Rajshekhar Chittoory

Comments and Discussions