1. Create User Control.
Create a C# Web Application by VS 2008
Add new User Control as you like show and compile it. Snapshot show you how it looks like.
2. Add existing user control to a web part and deploy web part.
Create a new web part by wss extension of vs 1.2
- Create a new folder "wpresources" in project. And add existing ascx file in this folder.
- Change web part CS file as below snappit.
- Change AssemblyInfo.cs file to add "using System.Security;" to the using part and add below snippet to the last row.
[assembly: AllowPartiallyTrustedCallers] - Change C:\Inetpub\wwwroot\wss\VirtualDirectories\portal.mysharepoint80\Web.Config file. Add SafeControl and change Trust Level as below
- Change the output path of project properties to
..\..\..\..\..\Inetpub\wwwroot\wss\VirtualDirectories\portal.mysharepoint80\bin\
- Build the project and copy WebUCOne.ascx file to folder
C:\Inetpub\wwwroot\wss\VirtualDirectories\portal.mysharepoint80\wpresources
- Run "iisreset -noforce" on command line
- Open [portal] -[site action]-[Gallery]-[Web Part Gallery]-[New], find the one you created and click [Populate Gallery].
- Add this web part to any page to show.
namespace UCPart{
[Guid("c60b2566-0113-490a-9581-8ecbac96a81a")]public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart
{public WebPart1()
{
}UserControl userControl;
protected override void CreateChildControls()
{
base.CreateChildControls();
userControl =
(UserControl)Page.LoadControl(@"/wpresources/WebUCOne.ascx");
this.Controls.Add(userControl);
}protected override void
Render(HtmlTextWriter writer)
{
//base.Render(writer);
userControl.RenderControl(writer);
} }}
No comments:
Post a Comment