VS 的 SharePoint 扩展 - 我拥有哪个版本?

发布于 2024-08-20 11:57:14 字数 1787 浏览 14 评论 0原文

我正在使用 Visual Studio 2008,并下载了 VSeWSS.exe 1.2,以启用 Web 部件开发。我是 SP 开发的新手,并且已经对 SP 的不同版本和 VS 附加组件的数量感到困惑。这个特殊问题的出现,凸显了我的困惑。

我选择添加->新项目->视觉 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);
        }
    }
}

我正在关注的书,Essential SharePoint 2007,作者 Jeff Webb,对于默认项目有以下内容 -

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");
        }
    }
}

我担心的真正原因是在本书的这一章中,作者经常提到“旧式”Web 部件和“新式”Web 部件之间的区别,如他对 Render 方法的评论中所述。

发生了什么事?为什么我的默认 Web 部件的作者签名不同?

I'm using Visual Studio 2008, and have downloaded VSeWSS.exe 1.2, to enable Web Part development. I am new to SP development, and am already bewildered by the number of different versions of SP, and the VS add-ons. This particular problem has come up, which highlights my confusion.

I selected Add -> New Project -> Visual C# -> SharePoint-> Web Part, accepted the defaults, and VS created a project, with the main file 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);
        }
    }
}

The book I'm following, Essential SharePoint 2007, by Jeff Webb, has the following for the default project -

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");
        }
    }
}

The real reason for my concern is that in this chapter of the book the author frequently mentions the distinction between "old style" web parts, and "new style" web parts, as noted in his comment on the Render method.

What's happened? Why has my default Web Part got a different signature to the authors?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

狼性发作 2024-08-27 11:57:14

作者对“新样式”Web 部件的区别在于,它们是 ASP.NET 2.0 Web 部件(2005 年发布),可以在 SharePoint 和 ASP.NET 中使用。旧样式 Web 部件特定于 SharePoint

  • 新样式 System.Web.UI.WebControls.WebParts.WebPart,可在 ASP.Net 2.0 (2005) 和 WSS 3.0 (2006) 中使用
  • 旧样式 Microsoft.SharePoint.WebPartPages.WebPart(仍然支持)

在问题的代码示例中,两个 Web 部件都是新样式,即。它们是 ASP.NET Web 部件。唯一的区别是 Visual Studio 覆盖了与本书不同的方法。然而,这两种方法以及许多其他方法,例如。 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)以添加功能。

在大多数 Web 部件中,Render 方法不会被重写。

The distinction the author is making with "new style" web parts is that they are the ASP.NET 2.0 web parts (released in 2005), which can be used in both SharePoint and ASP.NET. The old style web parts were specific to SharePoint

  • New style System.Web.UI.WebControls.WebParts.WebPart, available in ASP.Net 2.0 (2005) and WSS 3.0 (2006)
  • Old style Microsoft.SharePoint.WebPartPages.WebPart (still supported)

In the code samples in the question the two web parts are both new style, ie. they are ASP.NET Web Parts. The only difference is that visual studio has overidden a different method than the book has. However, both methods, and many others, eg. OnLoad, OnInit are available, and will be customised to get the web part to work.

My recommendation, after several months of web part development, is to use the first one as the basis for a "hello world" web part, ie.

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

And then start adding code to this method, or add other methods (eg. OnLoad, OnPrerender) to add functionality.

The Rendermethod would not overriden in most web parts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文