【问题标题】:SharePoint extensions for VS - which version have I got?VS 的 SharePoint 扩展 - 我有哪个版本?
【发布时间】:2011-01-13 07:41:42
【问题描述】:

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

我选择了添加 -> 新建项目 -> Visual C# -> SharePoint-> Web Part,接受默认值,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 部件的签名与作者不同?

【问题讨论】:

  • 无关:版本 1.3 可用:microsoft.com/downloads/…
  • 谢谢。我在安装 1.2 时遇到了一些麻烦,所以一旦它开始工作,我就不想冒险尝试 1.3。我查看了 1.3 的更改说明,它们似乎与此问题无关。由于 2009 年发布了 1.3,而我的书是 2007 年,因此我的 VSeWSS 或这本书的版本不太可能是 1.3。
  • 我感觉他(作者的)代码是针对 VSeWSS 1.0 或 1.1 的,这就是他所说的“新风格”,而我的 1.2 代码是一种“新的新风格”,并取代它。仍在尝试查找此版本的“入门”指南。
  • 我从来没有找到这个问题的答案。我被困在部署上,为了解决这个问题,我开始使用 WSPBuilder。它带有自己的默认 C# 项目,该项目生成一个“Hello World”Web 部件。它接近问题中的第一个程序。

标签: sharepoint-2007 web-parts wss-3.0 vsewss


【解决方案1】:

作者与“新型”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 部件。唯一的区别是视觉工作室覆盖了与本书不同的方法。但是,这两种方法以及许多其他方法,例如。 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 部件中被覆盖。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-05
    • 1970-01-01
    • 2017-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多