Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Thursday, December 01, 2011

How to deploy a User Control in SharePoint 2007


 How to deploy a User Control in SharePoint 2007
1. Open Visual studio 2005 or visual studio 2008
2. Create one user control.
3. Now logon to your SharePoint server
4. Go to “C:\Program Files\common files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS” Path & copy your webusercontrol along with its cs.
5. Now got your WebPart & add the following code.

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Security;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
[assembly:AllowPartiallyTrustedCallers]
namespace TestWebPart007
{
[Guid("7aa471f1-0297-4ffc-8191-9c192199273f")]
public class TestWebPart007 : System.Web.UI.WebControls.WebParts.WebPart
{
string strError = string.Empty;
Control myControl;
public TestWebPart007()
{
}
protected override void Render(HtmlTextWriter writer)
{
writer.Write(strError);
try
{
myControl.RenderControl(writer);
}
catch (Exception ex)
{
writer.Write(ex.ToString());
}
}
protected override void CreateChildControls()
{
try
{
this.Controls.Clear();
myControl = this.Page.LoadControl("\\_LAYOUTS\\Custom UserControls\\WebUserControl.ascx");
myControl.ID = "myControl";
this.Controls.Add(myControl);
}
catch(Exception ex)
{
strError += ex.ToString();
}
}
}
}

No comments:

Post a Comment