醉清风

导航

公告

统计

2011年3月25日 #

SharePoint Server 2007/MOSS的文件目录结构

安装了MOSS2007后,所有与SharePoint相关的文件都放在本地目录C:\Program Files\Common Files\Microsoft Shared\web server extensions\12下面。

下面介绍一些主要的文件目录。

1、 ISAPI目录
此目录下面存放的是SharePoint自带的Web Services,我们也可以自定义Web Services封装在SharePoint里面。自定义Web Services方法见:Writing Custom Web Services for SharePoint Products and Technologies

2、 Resources目录
SharePoint有两个资源文件夹,目录分别为C:\Program Files\Common Files\MicrosoftShared\web server extensions\12\CONFIG\Resources和C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\Resources,本地化工作主要是编写Resourses里的文件,网站如果显示的一些标题或描述不符合我们的要求,那么可以通过修改资源文件里的
<Data Name="修改元素">
<Value>网站显示的内容</Value>
</Data>
要引用资源文件里面的内容,一般通过$Resources:开头。
例如:<%$Resources:sps,LayoutPageZone_TopZone%>
其中:sps表示资源文件名,与sps.zh-CN.resx相对应。LayoutPageZone_TopZone表示sps.zh-CN.resx文件中的
<Data Name="LayoutPageZone_TopZone">
<Value>顶部区域</Value>
</Data>
节点。
注:一般不推荐修改所有C:\Program Files\Common Files\Microsoft Shared\web server extensions\12目录下的文件,因为这样将给版本升级带来问题。要加入我们自定义的内容通过增加文件到相应的目录下即可。比如这里我们可以增加一个资源文件,把我们要修改的元素放在里面。

3、 TEMPLATE目录
这是一个最主要的目录。子目录介绍如下:
(1)、SiteTemplates目录
放置各种网站定义模板。每个网站定义模板都会有一个ONET.XML文件,它位于 C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\SiteTemplates\Site_Definition_Name\XML folder
ONET.XML有五个节:

1、NavBars:指定主页的顶部导航和左部导航
2、ListTemplates:指定该站点可创建的各种列表(自定义列表、文档库、图片库等)
3、DocumentTemplates:指定在创建文档库时可以创建的文档模板(Microsoft Office Word 文档、Microsoft Office FrontPage 网页、Microsoft Office Excel 电子表格等)
4、Configurations:指定站点在创建时默认生成的各种列表和模块
5、Modules:指定站点中默认包含的Web部件库

注意:修改ONET.XML后需要重新启动IIS,才可生效

实例:基于已有模板创建站点模板。
步骤:

1、打开C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates目录
2、复制粘贴一个SPS文件夹,改名为GASSPS
3、找到C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\2052\XML目录
4、在目录中创建一个名为WEBTEMPGASSPS.XML的文件,把下列XML粘贴到文件中

<?xml version="1.0" encoding="utf-8"?>
<!-- _lcid="2052" _version="12.0.4518" _dal="1" -->
<!-- _LocalBinding -->
<Templates xmlns:ows="Microsoft SharePoint">
<Template Name="GASSPS" ID="10001">
    <Configuration ID="0" Title="浙江天然气模板" Hidden="FALSE" ImageUrl=""
        Description="此模板用于初始化浙江天然气网站。" >
    </Configuration>
</Template>
</Templates>

5、重启IIS(iisreset)
6、打开创建站点页面,在“选择模板”节中多了一个“自定义”选项,下面就有我们刚添加的“浙江天然气模板”。


(2)、THEMES目录
放置各种网站主题。

实例:创建自定义的主题
步骤:

1、先找到 Theme 文件夹位置 C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\THEMES
2、复制一个 Theme 的文件夹如 CLASSIC 更改成自己要的名字如 GASTHEME
3、在文件夹中,将CLASSIC.INF 改成与自己文件夹相同的名字如 GASTHEME.INF
4、打开 GASTHEME.INF 将 title 改成与自己文件夹和文件名相同的名字如GASTHEME
5、找到 C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\2052\SPTHEMES.XML 文件,复制并粘贴一个<Templates>元素,修改里面的内容如下:

   <Templates>
              <TemplateID>GASTHEME</TemplateID>
               <DisplayName>天然气主题</DisplayName>
               <Description>天然气主题将被应用</Description>
               <Thumbnail>images/thwheat.gif</Thumbnail>
               <Preview>images/thwheat.gif</Preview>
</Templates>
上面两个图片是参考Wheat主题的图片,也可以改成自己的图片,图片存放位置 C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\IMAGES文件夹下

6、打开“网站设置”中“网站主题”,就可以找到我们刚刚添加的GASTHEME主題了。

(3)、LAYOUTS目录
网站所有的页面功能(网址后面有 _layouts的页面)都集中于此目录下面(除了模板中的Default.aspx以及某类型List相关页面)。可以添加自己的功能页面,方法:

(4)、ADMIN目录
管理中心的页面功能集中此目录下面。

(5)、CONTROLTEMPLATES目录
放置各种服务器控件。

(6)、IMAGES目录
放置网站用到的主要图片,如网站Logo等。

(7)、FEATURES目录
放置各种Feature,在MOSS 2007中feature功能之强大超乎想象,可以说对一个已有的网站功能性的增强最后多数都要通过feature来实现。包括母版页、内容页以及文档库等都是通过Feature来实现的。

实例1:使用Feature自定义母版页。
步骤:
1、          打开Feature目录C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES
2、          新建一个GASMASTERPAGES文件夹
3、          在GASMASTERPAGES文件夹下,新建Feature.xml文件,将下列内容粘贴到文件中
<!-- _lcid="1033" _version="12.0.4518" _dal="1" -->
<!-- _LocalBinding -->
<Feature Id="cbdddc58-c0e1-4d64-99bc-071379a910f3"
           Title="Gas Master"
           Description=""
           Version="12.0.0.0"
           Scope="Site"
           Hidden="False"
           DefaultResourceFile="core"
           xmlns="http://schemas.microsoft.com/sharepoint/">
    <ElementManifests>
         <ElementManifest Location="ProvisionedFiles.xml"/>
    </ElementManifests>
</Feature>
在这个XML文件中,以下关于Featrue的metadata 包含在Featrue 元素中。(更详细的信息请参阅Feature.xml Files
ID: 一个GUID,用于唯一标识这个Feature,可以通过VS生成
Title:Feature 的名字,可以在网站内关于Site Featrues的页面中看到。
Description:对description的描述。
Version:Feature的版本;
Scope:其值可以是Web或Site,它指明了这个Feature是应用于整个的Site Collection还是仅仅用于单独的一个子站点。
Hidden:值可以是True或False.该设置指定了这个Feature是否在Site Feature页面上显示。
DefaultResourceFile: 资源文件名字,Feature依赖它提供其它附加的配置信息。
Feature.xml文件中的<ElementManifests>元素,这个元素包含了另一个XML文件的位置,而这个文件包含的<Elemnets>的内容是Feature要实现的。
<ElementManifest>元素指明了要使用一个名为ProvisionedFiles.xml的文件,以下是该文件的<Elements>元素内容。


4、          在GASMASTERPAGES文件夹下,新建ProvisionedFiles.xml文件,将下列内容粘贴到文件中
<!-- _lcid="1033" _version="12.0.4518" _dal="1" -->
<!-- _LocalBinding -->
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
     <Module Name="OSGMasterPages" Url="_catalogs/masterpage" Path="MasterPages" RootWebOnly="TRUE">
         <File Url="Gasmaster.master" Type="GhostableInLibrary">
            <Property Name="ContentType" Value="" />
            <Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/Gas.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/Gas.png" />
            <Property Name="MasterPageDescription" Value="" />
       </File>
</Module>
<Module Name="PublishingLayoutsPreviewImages" Url="_catalogs/masterpage" IncludeFolders="??-??" Path="" RootWebOnly="TRUE">
        <File Url="Gas.png" Name="Preview Images/Gas.png" Type="GhostableInLibrary">
        </File>
     </Module>
</Elements>
5、          新建MasterPages和zh-cn文件夹,在MasterPages文件夹中新建Gasmaster.master文件,在zh-cn文件夹中放入一张模板页的图片Gas.png
6、          重启IIS(iisreset)
7、          在SharePoint服务器上运行CMD.exe,
输入命令切换目录:cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
安装Feature输入命令:stsadm -o installfeature -filename GASMASTERPAGES
激活Feature输入命令:stsadm -o activatefeature -filename GASMASTERPAGES\feature.xml -url http://portal:8000
8、          打开“网站设置”中“母版页”,就可以看到我们刚刚添加的Gasmaster.master母版。
参考连接:Create a Feature: Add Custom Master Pages to your Site Collections

实例2:使用Feature定义站点中的菜单项
包括其中第一个CustomAction在“网站设置”页面中的“外观”标题下创建了一个自定义链接.第二个CustomAction在页面的“网站操作”菜单下增加了一个用户自定义菜单项.第三个CustomAction在文档库的“新建”下拉菜单下创建了一个自定义菜单项.第四个CustomAction在文档库的“操作”下拉菜单下创建了一个自定义菜单项。
步骤:
1、创建一个Feature.xml文件
在Features目录下创建一个目录例如MyMenu,在其中创建一个Feature.xml文件,文件内容如下:
<?xml version="1.0" encoding="utf-8" ?>
<!-- _lcid="1033" _version="12.0.4017" _dal="1" -->
<!-- _LocalBinding -->
<Feature Id="6098EC11-8128-409A-8D2C-414E93F67DD4"
             Title="$Resources:GasMenu,MenuTitle;"
             Description="$Resources:GasMenu,MenuDescription;"
             Version="12.0.0.0"
             Scope="Web"
            Hidden="FALSE"
            DefaultResourceFile="customDocumentLibrary"
             xmlns="http://schemas.microsoft.com/sharepoint/">
             <ElementManifests>
                 <ElementManifest Location="LightUp.xml" />
             </ElementManifests>
</Feature>
2、在C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\Resources文件夹中新建GasMenu.zh-CN.resx文件,输入以下内容
<?xml version="1.0" encoding="utf-8"?>
<!-- _lcid="2052" _version="12.0.4518.1016" _dal="1" -->
<!-- _LocalBinding -->
<root>
<Data Name="MenuTitle">
<Value>天然气菜单项</Value>
</Data>
<Data Name="MenuDescription">
<Value>添加了四个菜单项,分别为在“网站设置”页面中的“外观”标题下创建了一个自定义链接、在页面的“网站操作”菜单下增加了一个用户自定义菜单项、在文档库的“新建”下拉菜单下创建了一个自定义菜单项和在文档库的“操作”下拉菜单下创建了一个自定义菜单项。</Value>
</Data>
</root>
    3、创建Feature的描述文件LightUp.xml
文档的内容如下:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- create command link site setting page -->
<CustomAction Id="SiteSettings" GroupId="Customization"
                 Location="Microsoft.SharePoint.SiteSettings"
                             Sequence="106"
                             Title="Custom Site Setting Command">
                             <UrlAction Url=""/>
      </CustomAction>
      <!-- Add command to site action dropdow -->
         <CustomAction Id="SiteActionsToolbar"
                        GroupId="SiteActions"
                                    Location="Microsoft.SharePoint.StandardMenu"
                                    Sequence="1000"
                                    Title="Custom Action"
                                    Description="custom site action"
                                    ImageUrl="/_layouts/images/ACG16.GIF">
                                    <UrlAction Url=""/>
     </CustomAction>
        <!-- Document Library Toolbar New Menu DropDown -->
        <CustomAction Id="DocLibNewToolbar"
                RegistrationType="List"
                      RegistrationId="101"
                      GroupId="NewMenu"
                      Rights="ManagePermissions"
                      Location="Microsoft.SharePoint.StandardMenu"
                      Sequence="1000"
                      Title="Custom New Command"
                      Description="custom new command "
                      ImageUrl="/_layouts/images/ACG16.GIF">
                      <UrlAction Url=""/>
     </CustomAction>
        <!-- Document library Toolbar Actions Menu Dropdown -->
        <CustomAction Id="DocLibActionsToolbar"
                RegistrationType="List"
                      RegistrationId="101"
                      GroupId="ActionsMenu"
                      Rights="ManagePermissions"
                      Location="Microsoft.SharePoint.StandardMenu"
                      Sequence="1000"
                      Title="Command on Document Library"
                      Description=" command on document library"
                      ImageUrl="/_layouts/images/ACG16.GIF">
                      <UrlAction Url=""/>
          </CustomAction>
</Elements>
4、重启IIS(iisreset)
5、在SharePoint服务器上运行CMD.exe,
输入命令切换目录:cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
安装Feature输入命令:stsadm -o installfeature -filename MyMenu
激活Feature输入命令:stsadm -o activatefeature -filename MyMenu\feature.xml -url http://portal:8000
疑问:在Feature.xml中,虽然把编码方式改为encoding="GB2312",但是使用汉字都不能识别出来,可是在LightUp.xml文件中虽然编
方式为encoding="UTF-8",但是使用汉字都能识别出来,感觉很奇怪。

实例3:使用Feature创建用户控件。
请看KaneBoy的 DelegateControl:SharePoint Server 2007内置的一个“用户控件包装器”

实例4:使用Feature创建自定义的文档库。
请看宋振乾的 如何在MOSS2007中创建一个定制的 Document Library Feature

posted @ 2011-03-25 17:09 醉清风 阅读(195) 评论(0) 编辑

Working with BeforeProperties and AfterProperties on SPItemEventReceiver

As many of you know, event receivers are a great way to hook into various SharePoint events.  These can apply to Feature events such as FeatureActivated, List events such as FieldAdded, and many others.  The most common set of receivers used, however, are part of SPItemEventReceiver which let you wire your code up to a number of events that can occur to items on a list or library.

When working with events, you’ll quickly find that before (synchronous) and after (asynchronous) events exist, and the method suffix such as “ing” (e.g. ItemAdding) and “ed” (e.g. ItemAdded) will tell you whether it gets invoked before or after the actual change is made.  Basic stuff.

And, as you get deeper, you’ll even find that you can extract the before and after state of the change.  For example, you can hook into the ItemUpdating event for a document library and prevent a user from changing a certain column.  The code might look like this:

public override void  ItemUpdating(SPItemEventProperties properties)
{
     if (properties.BeforeProperties["column"] != properties.AfterProperties["column"])
    {
        properties.Cancel = true;
        properties.ErrorMessage = "This column cannot be changed";
    }
}

For a document library, this works just fine.  However, you should know that the BeforeProperties hash table is not populated for items on a list.  As is worded in the SDK: “For documents, Before and After properties are guaranteed for post events, such as ItemUpdated, but Before properties are not available for post events on list items”

When they say “not available for post events on list items”, do they mean after events (like ItemUpdated, ItemDeleted, etc)?  The wording is curious here, so I thought I’d take some time to test each combination of common events such as Add, Update and Delete.  These were done across a custom list and then a document library.  Each test involved adding a new item, editing the item and then deleting the item.  Here are the results for a list:

List BeforeProperties AfterProperties properties.ListItem
ItemAdding No value New value Null
ItemAdded No value New value New value
ItemUpdating No value Changed value Original value
ItemUpdated No value Changed value Changed value
ItemDeleting No value No value Original value
ItemDeleted No value No value Null

No value means that column value in the hash table was not available. 
New value means that the correct value for the column was available. 
Changed value means that the correct updated value was available.
Original value means that the correct original value was available.

Here is the same test against a document library:

Library BeforeProperties AfterProperties properties.ListItem
ItemAdding No value No value Null
ItemAdded No value No value New value
ItemUpdating Original value Changed value Original value
ItemUpdated Original value Changed value Changed value
ItemDeleting No value No value Original value
ItemDeleted No value No value Null


Properties.ListItem refers the the current value for the list item at that point in the event.  Null means that the item is not available.  My analysis yields the following results:


So, if we go back to our original problem listed above.  How can we prevent a user from changing a certain column for an item in a list event?  From the list table, you can see if we hook into the ItemUpdating event, we can compare the current item’s value (properties.ListItem) to the AfterProperties value.  The code would look like this:

if (properties.ListItem["column"] != properties.AfterProperties["column"])
{
    properties.Cancel = true;
    properties.ErrorMessage = "This column cannot be changed";
}

I hope this post gives you a better idea of how before and after events work for both lists and libraries.  Your comments and feedback are always welcomed.

Reprinted http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?ID=25

posted @ 2011-03-25 16:00 醉清风 阅读(119) 评论(0) 编辑