2010-02-04 60 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部件中都不会覆盖。

  • 相关问题