Develop and deploy WSS WebParts in one solution

水深无声 2021-11-29 07:06 304阅读 0赞

There is one question always bother me these days: How to develop and deploy WSS webparts in one solution using the WSS extension for the VS2005? This solution should consist of such files:

  • The Web Part classes.
  • The web user control (.ascx files)

Today I found a easy way to realize what I need. (However, you could package these things into one solution manually, but that is a little bit complicated.)

First, Create a webpart project using the WSS add-in for VS2005. If you don’t know how to do this, read Creating a Windows SharePoint Services 3.0 Web Part Using Visual Studio 2005 Extensions.

You could add another webpart project, and the add-in will deploy them together when you click deploy.

Now, add another project, called “Module” project, this project is used to provision files, I shall put my web user control in this project later.

Create another project, and create a user control, I build a simple control which just let the label control display the text in the textbox. The simple code is like this:

  1. <script runat="server">
  2. Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  3. Me.Label1.Text = Me.TextBox1.Text
  4. End Sub
  5. </script>
  6. <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  7. <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
  8. <br />
  9. <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

Then, in the Module.xml file, I change the configuration.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- _filecategory="Module" _filetype="File" _filename="module.xml" _uniqueid="aa01ed93-8312-48ea-a798-6645071c35c7" -->
  3. <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  4. <Module Name="Module1" Url="Controls" Path="">
  5. <File Url="sample.txt" />
  6. <File Url="MyControl.ascx" />
  7. </Module>
  8. </Elements>

Then, in one of my web part class, I could use the control like this:

  1. protected override void CreateChildControls()
  2. {
  3. Controls.Clear();
  4. Controls.Add(Page.LoadControl("~/Controls/MyControl.ascx"));
  5. this.EnsureChildControls();
  6. }

The project look like this.

clip\_image001

When deployed, there should be 3 features in the solution, consists of two webparts and a Module. I think this could reduce the deploy work when developing a webpart which using a custom web user control.

However, I didn’t do much test work, if you find any problems with this method. Please feel free to tell me, thanks.

转载于:https://www.cnblogs.com/Glen/archive/2007/08/21/864256.html

发表评论

表情:
评论列表 (有 0 条评论,304人围观)

还没有评论,来说两句吧...

相关阅读