2010-02-04 32 views
0

我正在使用Visual Studio 2008,並下載了VSeWSS.exe 1.2,以啓用Web部件開發。我是SP開發新手,並且已經被不同版本的SP的數量和VS附加組件所困惑。這個問題已經出現,這突出了我的困惑。VS的SharePoint擴展 - 我得到了哪個版本?

我選擇添加 - >新建項目 - >的Visual C# - > SharePoint的> Web部件,接受默認設置,並VS創建了一個項目,與主文件WebPart1.cs

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 Microsoft.SharePoint; 
using Microsoft.SharePoint.WebControls; 
using Microsoft.SharePoint.WebPartPages; 

namespace WebPart1 
{ 
    [Guid("9bd7e74c-280b-44d4-baa1-9271679657a0")] 
    public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart 
    { 
     public WebPart1() 
     { 
     } 

     protected override void CreateChildControls() // <-- This line 
     { 
      base.CreateChildControls(); 

      // TODO: add custom rendering code here. 
      // Label label = new Label(); 
      // label.Text = "Hello World"; 
      // this.Controls.Add(label); 
     } 
    } 
} 

這本書我「M以下,基本的SharePoint 2007年,傑夫·韋伯,具有默認的項目如下 -

using System; 
<...as previously> 

namespace WebPart1 
{ 
    [Guid("9bd7e74c-280b-44d4-baa1-9271679657a0")] 
    public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart 
    { 
     //^this is a new style (ASP.NET) web part! [author's comment] 
     protected override void Render(HtmlTextWriter writer) // <-- This line 
     { 
      // This method draws the web part 
      // TODO: add custom rendering code here. 
      // writer.Write("Output HTML"); 
     } 
    } 
} 

我關注的真正原因是,這本書的這一章中筆者經常提到的「老之間的區別風格「的網頁部分,以及」新風格「的網頁部分,正如他的文章所述評論Render方法。

發生了什麼事?爲什麼我的默認Web部件與作者有不同的簽名?

+1

無關:版本1.3可用:http://www.microsoft.com/downloads/details.aspx?familyid=FB9D4B85-DA2A-432E-91FB-D505199C49F6&displaylang=en – 2010-02-05 00:02:56

+0

謝謝。我在安裝1.2時遇到了一些麻煩,所以一旦運行,我不想冒1.3版的風險。我已經瀏覽了1.3版的變更註釋,並且他們似乎沒有涉及到這個問題。由於1.3在2009年推出,而我的書是2007年,我的VSeWSS或本書的版本不可能是1.3。 – 2010-02-05 01:00:10

+0

我感覺他的(作者的)代碼是針對VSeWSS 1.0或1.1的,這​​就是他所說的「新風格」,我的代碼1.2是一種「新的新風格」,並取代它。仍試圖找到此版本的「入門指南」。 – 2010-02-05 01:06:51

回答

0

作者與「新風格」Web部件的區別在於它們是ASP.NET 2.0 Web部件(2005年發佈),可以在SharePoint和ASP.NET中使用。舊式的Web部件在ASP.Net 2.0(2005年)和WSS 3.0(2006)

  • 是特定於SharePoint

    • 新款 System.Web.UI.WebControls.WebParts.WebPart,可用老式 Microsoft.SharePoint.WebPartPages.WebPart(仍支持)

    在問題的代碼示例兩個Web部件都是新的風格,即。他們是ASP.NET Web部件。唯一的區別是,視覺工作室已經推出了與書中不同的方法。但是,這兩種方法,以及其他許多方法,例如。 OnLoad,OnInit是可用的,並且將被定製以使Web部件工作。

    經過幾個月的Web部件開發,我的建議是使用第一個作爲「hello world」Web部件的基礎,即。

     protected override void CreateChildControls() 
        { 
         base.CreateChildControls(); 
         Label label = new Label(); 
         label.Text = "Hello World"; 
         this.Controls.Add(label); 
        } 
    

    然後開始添加代碼以這種方法,或者添加其他的方法(例如,的OnLoad,的OnPreRender)以添加功能。

    Render方法在大多數Web部件中都不會覆蓋。

  • 相關問題