惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Jina AI
Jina AI
云风的 BLOG
云风的 BLOG
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
J
Java Code Geeks
博客园 - 聂微东
B
Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
腾讯CDC
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
Microsoft Azure Blog
Microsoft Azure Blog
D
DataBreaches.Net
The GitHub Blog
The GitHub Blog
美团技术团队
博客园 - Franky
Google DeepMind News
Google DeepMind News
V
V2EX
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
The Cloudflare Blog

博客园 - choral

BLOG迁移通知………… Hello Boston [Tech-Ed 2006 Day 5] Hello Boston [Tech-Ed 2006 Day 4] Hello Boston [Tech-Ed 2006 Day 3] Hello Boston [Tech-Ed 2006 Day 2] Hello Boston [Tech-Ed 2006 Day 1] Tech-Ed 2006 is ready to go ! 今天发现的两个很酷的东西 OSS2007 SDK Released ~~ OSS2007 beta2 LOADed! 给SharePoint Portal Server 2003 加装登陆按钮的最简解决方案 来自ODC06的中文快讯 Office2007将名副其实 WSSv2的站点模板制作教程 SharePointV3,即Office SharePoint Server 2007的一些新特性透露! Kaneboy的用户控件包装器Hands-On-Lab更新咯! 了不起的Kaneboy发布了用户控件包装器的Hands-On-Lab! 神秘大师终于出手:WebPart中文管理工具 有关SharePoint单点登陆(Single Sign On)的一个开发样例
在Office SharePoint Server 2007上创建自己的WebPart!
choral · 2006-05-19 · via 博客园 - choral

不说废话了,首先,我参考了Muller的这篇文章:
http://blogs.tamtam.nl/mart/CommentView,guid,a34071a0-ad27-44c7-aa78-3f956d6f920e.aspx

做法也基本照抄:
1、打开VS2005,新建工程(Class Library)
2、引用System.Web,Microsoft.SharePoint.dll,并将当前开发的类继承自:System.Web.UI.WebControls.WebParts.WebPart
3、重载Render函数:protected override void Render(HtmlTextWriter writer)
4、在Render中加入自己的代码:

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint;

namespace NewWebPart
{
    
public class ChoralPart : System.Web.UI.WebControls.WebParts.WebPart
    
{
        
protected override void Render(HtmlTextWriter writer)
        
{
            writer.Write(
"Hello, world!<br>");
            SPWeb web 
= SPControl.GetContextWeb(Context);
            writer.Write(
"You're visiting the site: " + web.Title);
        }

    }

}

可以看出来,获取当前网站等操作仍然延续从前的方法。

5、使用强命名编译(在工程属性中选择“signing”,新建key)
6、将此dll拖到GAC的目录中:c:\windows\assemblies
7、在Web.Config里加入此WebPart的注册信息:
例如:<SafeControl Assembly="NewWebPart, Version=1.0.0.1, Culture=neutral, PublicKeyToken=785180fe41b26686" Namespace="NewWebPart" TypeName="*" Safe="True" />
:我的环境下这个web.config位置(即IIS上WSS3的虚拟目录)为:
C:\Inetpub\wwwroot\wss\VirtualDirectories\3eb911e5-7223-4f5a-b1cf-46d53ee65b52
不知道是测试版的原因还是什么?也可能是因为我安装的时候旧的WSS没有卸载。
8、在网站集管理页面中,选择Galleries的Web Parts
9、点击“New”
10、选中自己的webpart,点击Populate Gallery,此webpart就可以在网站上使用了。
11、将此webpart添加到首页:

另外,我尝试了将此WebPart部署到Bin目录里,也修改了web.config的trust level,重启了IIS,但始终报AllowPartiallyTrustedCallersAttribute的错误。