Use several Web Part deployment methods of ASP. NET:
1. Use the Web Part deployment method of ASP. NET 2.0 to declare SafeContorl and upload it to the Webpart gallery of Sharepoint. The Walkthrough on MSDN: Creating a Basic Web Part is described in detail.
2. after using the SharePoint Webpart to install VS Extensions for SharePoint, a project type is called webpart, write a webpart, and then F5, The webpart will be deployed to your SharePoint site. A Feature is actually deployed. its principles are also introduced on MSDN: Walkthrough: Creating a Basic SharePoint Web Part
3. In his blog, kaneboy mentioned the use of Feature deployment of DelegateContorl to deploy an ascx file to the site set Feature.
The above three methods have their own advantages and disadvantages. The first two methods use pure Webpart form, which is very troublesome for development, especially for some rich user interfaces. The third method solves the shortcomings of the first two methods, but there is no Code-behind. It is not suitable for enterprise-level development to write code in the ascx file, it is not convenient to use Feature for management after deployment. So today I am going to Demo a way to use the Code-behind user control as a WebPart, And the deployed UserContorl is easy to manage.
Here we use a tool named SmartPart, which is available in the WSS 2.0 era and is now available for versions with WSS 3.0. I downloaded an msi installation package. I don't know why I didn't install the package successfully on both vpcs. After extracting the package to the temporary directory, it didn't reflect it. No way, some have to do it yourself. There is a Cab file in the temporary directory. After Opening this file, I will study it and understand the installation steps.
Step (1): deploy SmartPart. dll to GAC.
Step (2): create a Web Project and develop your user control. The user control of the Demo is called UCPart. ascx.
Front-end code:
- <%@ Control Language="C#" CodeFile="UCPart.ascx.cs" Inherits=
"DemoWebPart.UCPart" CompilationMode="Always" %>
- <asp:TextBox ID="txbDate" runat="server">
- </asp:TextBox>
Background code:
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- namespace DemoWebPart
- {
- public partial class UCPart : System.Web.UI.UserControl
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- this.txbDate.Text = DateTime.Now.ToShortDateString();
- }
- }
- }
The function is simple, that is, assigning a value to a textbox in the background code. After compilation, copy the user control along with the background code file to <% IIS Root Dir %> \ wss \ VirtualDirectories \ xxxx \ UserContorls.
<% IIS Root Dir %> is the Root directory of IIS, and xxxx is the port number of the current Web Application. If you do this for the first time, you need to create a UserContorls folder manually.
- <SafeControl Assembly="SmartPart, Version=1.1.0.0, Culture=neutral,
PublicKeyToken=dd064a5b12b5277a" Namespace="SmartPart" TypeName="*" />
At the same time, modify <% IIS Root Dir %> \ wss \ VirtualDirectories \ xxxx \ Web. Config. Declare SaftContorl. The preceding section describes how to deploy ASP. NET Webpart.
- ASP. NET calls the WCF Service
- Analysis of ASP. NET verification controls
- Compatibility between the WCF Service and ASMX service in ASP. NET
- ASP. NET Applications
- ASP. NET HttpModule