往sharepoint中添加aspx页面有几种方式
1.在designer中添加好页面,然后加上后台代码
参考: http://bbs.winos.cn/thread-36766-1-1.html
为sharepoint页面添加后台代码
我们知道,存储在数据库里的SharePoint页面是不能直接添加后台代码的,这给我们带来了很多的不方便,比如想要在页面上实现一些东西,都必须使用Webpart或者自定义控件的方式,哪怕仅仅是很简单的几行后台代码。而WSS 3.0 是基于ASP.NET 2.0的,在ASP.NET站点里使用的任何技术在WSS站点里同样可以使用。因此我们同样可以给WSS站点的页面添加后台代码。 存储在数据库中的sharepoint页面分为两部门,母板页和内容页,我们可以为这两种页面分别添加后台代码。实现方式不一样,若为内容页添加后台代码,我们需要继承自Microsoft.SharePoint.Publishing.PublishingLayoutPage类,若为母板页添加后台代码,我们需要继承自System.Web.UI.MasterPage类,你应该将后台代码类与对应页面设置成相同的名字,但这不是必须的。如下所示:
这样我们就可以为页面上的控件添加相应的后台代码。比方说我们的页面上有一个按钮和一个文本框,ID分别为textbox1和button1,并为button添加一个ckick事件,当点击按钮时,将当前时间写入文本框中,可以这么来写:
在MOSS的页面上,服务器控件分为ASP控件(命名空间System.Web.UI.WebControls)和sharepoint控件(命名空间是Microsoft.SharePoint.WebControls),我们同样可以声明sharepoint控件并为它们添加相应的操作。 写好我们的后台代码后,将代码生成到对应的bin目录下(或者GAC,记得强命名),在web.config文件中添加一行,<SafeControl Assembly="" Namespace="" TypeName="*" Safe="True" />,其中assembly和namespace可以通过reflector获得,然后我们还需要在页面上重写页:
如果是母板页,这样添加
不过重写了之后,就不能在设计窗口中打开页面了。 通过这种方式,开发者就可以在像ASP.NET中一样做开发,例如我们可以重写onload事件来实现向页面的控件绑定数据。 有兴趣的朋友可以尝试一下,能满足我们很多的需求。 MSDN参考地址:http://msdn.microsoft.com/en-us/library/bb986729.aspx |
2. 用feature的形式发布网页,其中的dll文件可以放在GAC中也可以放在虚拟目录的bin目录中
参考: http://www.cnblogs.com/Sunmoonfire/archive/2008/04/10/1146975.html
http://www.cnblogs.com/zxjay/archive/2008/11/16/Xianfen_Net_SharePoint_4.html
http://www.cnblogs.com/Roy_Cao/articles/1926815.html
可以通过新建一个 ASP.Net Web Application (不是新建Site) 来预先做好页面并生成相应的dll.
其中后台代码可以用默认的继承
System.Web.UI.Page
也可以用新的
Microsoft.SharePoint.WebPartPages.WebPartPage 或
Microsoft.SharePoint.Publishing.PublishingLayoutPage (需引用using Microsoft.SharePoint.Publishing;)
然后修改aspx页面,加入模板页的引用,删除head,body,form的定义(子页不能有这些定义).
<%@ Page Language="C#" masterpagefile="~masterurl/default.master" title="It" inherits="WebApplication1._Default,WebApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" meta:webpartpageexpansion="full" meta:progid="SharePoint.WebPartPage.Document" %>
<asp:Content id="Content1" runat="Server" contentplaceholderid="PlaceHolderMain">
</asp:Content>
在C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\ 新建一个目录,名称为要新增的feature的名字.
新建2个文件
feature.xml
elements.xml
1个文件夹,用来存放我们的aspx页面
我们可以这样组织feature.xml内容:
<?xml version="1.0" encoding="utf-8" ?>
<feature id="{AAA4124D-2A89-43df-8427-F820D7B20CC9}" title="FileUploadDemo" xmlns="http://schemas.microsoft.com/sharepoint/" hidden="FALSE" scope="Web" version="1.0.0.0" description="Loads a file into sharepoint site" creator="">
<elementmanifests>
<elementmanifest location="elements.xml" />
<elementfile location="custompages\custompage1.aspx" />
<elementfile location="custompages\custompage2.aspx" />
</elementmanifests>
</feature>
elements.xml内容如下:
<?xml version="1.0" encoding="utf-8" ?>
<elements xmlns="http://schemas.microsoft.com/sharepoint/">
<module path="custompages" name="CustomPages">
<file path="custompage1.aspx" name="" type="Ghostable" url="custompages/custompage1.aspx" />
<file path="custompage2.aspx" name="" type="Ghostable" url="custompages/custompage2.aspx" />
</module>
</elements>
将dll考到相应端口的虚拟目录的bin目录下
要让页面正常运行,我们还需要在sahrepoint网站的webconfig文件中添加安全控件
<SafeControl Assembly="myCusotmPageWithModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" Namespace="myCusotmPageWithModule" TypeName="*" Safe="True" />
一切就绪后,安装feature:
stsadm -o installfeature -name customapp
如需更新可先删再安装
stsadm -o uninstallfeature -name customapp
然后到某个SharePoint站点(如 http://mossdemo/onesite)上,激活该Feature。
现在,就可以通过如下feature中定义的路径访问我们的aspx页面了.(如 http://mossdemo/onesite/custompages/custompage1.aspx )