zoukankan      html  css  js  c++  java
  • 在MOSS中开发一个模块化的feature

    moss中的feature功能很强大,本文主要看一下如何开发一个模块化的feature。
    比如可以把一个学生管理功能(包括aspx页面等)开发成一个feature,然后可以在不同的moss网站中有选择的激活这个feature,激活后就把对应的链接加入此网站的首页上,以此实现功能的动态加载。

    为了方便说明,先列出我的文件结构:
    Feature.dll
    Install.bat
    Template
                --Student
                              --elements.xml
                              --feature.xml
                              --Student
                                            --StudentList.aspx
                                            --UserEdit.aspx


    首先我们在sharepoint designer中定制两个aspx页面:StudentList.aspx和UserEdit.aspx
    (要保证这两个页面在moss站点中是能够正常访问的)
    我这里只是演示feature的功能,就两个页面的代码就不列出了。

    然后就是feature配置文件的写法
    对于MOSS中的feature我们一般都要写两个配置文件:

    <Feature
      
    Id="4292625E-5811-47a4-9B88-58A206C53515"
      Title
    ="学生管理-测试"
      Description
    ="学生管理-测试。"
      Scope
    ="Web"
      Hidden
    ="false"
      ReceiverAssembly
    ="Feature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=48fca413ed4dd464"
      ReceiverClass
    ="Feature.StudentFeature"
      xmlns
    ="http://schemas.microsoft.com/sharepoint/">

        
    <ElementManifests>
            
    <ElementManifest Location="elements.xml"/>
        
    </ElementManifests>

    </Feature>

    其中ReceiverAssembly和ReceiverClass是指定feature激活等操作时对应的代码文件的,后面会提到

    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
        
    <!-- Path指的是Template\Features下的实际路径 Url指的是MOSS站点的虚拟路径 -->
        
    <Module Path="Student" Url="Student" >
            
    <!-- 一览页面 -->
            
    <File Url="StudentList.aspx"  Type="Ghostable" />
            
    <!-- 编辑页面 -->
            
    <File Url="UserEdit.aspx" Type="Ghostable" />
        
    </Module>
    </Elements>
    特别要注意的是我文件中的注释

    然后就是Feature对应的Receiver代码
    主要作用是在feature激活时把链接加到网站首页上,在停止时把feature对应的aspx页面从网站中删除(激活feature时会根据配置自动把文件复制到MOSS网站里)
        public class StudentFeature : SPFeatureReceiver
        
    {
            
    public override void FeatureActivated(SPFeatureReceiverProperties properties)
            
    {

                
    // get a hold off current site in context of feature activation
                SPWeb site = (SPWeb)properties.Feature.Parent;
                SPNavigationNodeCollection topNav 
    = site.Navigation.QuickLaunch;

                
    // create dropdown menu for custom site pages
                topNav[0].Children.AddAsLast(new SPNavigationNode("学生管理""Student/StudentList.aspx"));
            }



            
    public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
            
    {

                SPWeb site 
    = (SPWeb)properties.Feature.Parent;
                
    // delete folder of site pages provisioned during activation
                SPFolder sitePagesFolder = site.GetFolder("Student");
                sitePagesFolder.Delete();

                SPNavigationNodeCollection topNav 
    = site.Navigation.QuickLaunch;

                
    for (int i = topNav[0].Children.Count - 1; i >= 0; i--)
                
    {
                    
    if (topNav[0].Children[i].Title == "学生管理")
                    
    {
                        
    // delete node
                        topNav[0].Children[i].Delete();
                    }

                }

            }


            
    public override void FeatureInstalled(SPFeatureReceiverProperties properties)
            
    {
            }


            
    public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
            
    {
            }

        }
    代码没什么特殊的地方,就是使用了MOSS的object model进行操作

    最后就是进行部署了
     1@SET TEMPLATEDIR="c:\program files\common files\microsoft shared\web server extensions\12\Template\Features"
     2@SET STSADM="c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm"
     3@SET GACUTIL="c:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe"
     4
     5Echo Installing CustomSitePages.dll in GAC
     6%GACUTIL% -if Feature.dll
     7
     8Echo Copying files to TEMPLATE directory
     9xcopy //y TEMPLATE\* %TEMPLATEDIR%
    10
    11Echo Installing feature
    12%STSADM% -o installfeature -filename  Student\feature.xml -force
    13
    14IISRESET
    15REM cscript c:\windows\system32\iisapp.vbs /"SharePointDefaultAppPool" /r
    16
    17
    第六行注册GAC
    第九行复制文件
    12行安装feature

    安装好之后在需要的网站上激活这个feature就可以了
  • 相关阅读:
    php method_exists( $object , string $method_name )
    php伪类型 (mixed)
    6.6-2-数组与数据结构(用数组及其函数实现堆栈等数据结构)
    6.6-1-php数组相关(2)
    2017.6.5-2-php数组相关(1)
    2017.6.5-1-php函数应用及流程控制
    CodePage
    bat批处理教程
    pip安装及源
    CentOS安装Python3
  • 原文地址:https://www.cnblogs.com/IsNull/p/1701589.html
Copyright © 2011-2022 走看看