• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
C罗.net
DotNetNuke vs SharePoint
博客园    首页    新随笔    联系   管理    订阅  订阅

将Infopath表单模板打包成Sharepoint的Solution进行部署

   我们在部署浏览器兼容的Infopath表单模板时常常会遇到需要管理员审批的问题,要正常使用这样的表单模板,我们需要通过Sharepoint的管理中心上传此表单或执行stsadm -o uploadformtemplate后才能正常使用,这个过程是相当的麻烦,尤其是当有多个表单模板需要部署时。如果你曾仔细留意过的话,你会发现当你通过管理中心上传表单后,Sharepoint实际上会自动创建出一个solution,在Solution Management中会看到以form开头的solution,在feature目录中也能找到与此solution对应的文件。那么我们是否可以将表单模板先打包成solution再通过stsadm -o addsolution来进行部署呢?
    跟制作其他类型的wsp文件类似,我们需要这样几个文件:
    1.发布过的浏览器兼容的Infopath表单(如果表单带有代码,还需要编译后的dll文件)
    2.manifest.xml
    3.feature.xml
    4.elements.xml
    5.solution.ddf

    如何发布与浏览器兼容的Infopath表单不在本文讨论的范围之内,此处不再赘述。

    manifest.xml:这个文件是WSS识别wsp的关键文件,它必须命名为manifest.xml,它的内容会类似于下面这些:
    <Solution SolutionId="31009326-31C2-4a43-B740-42405EFB8DD2" xmlns="http://schemas.microsoft.com/sharepoint/">
      
<FeatureManifests>
        
<FeatureManifest Location="ExpenseRequestTemplate\feature.xml" />
      
</FeatureManifests>
    
</Solution>

   
当你制作自己的manifest.xml时,请确保生成了一个新的SolutionID。

    feature.xml: 这个文件名请确保跟manifest.xml中FeatureManifest节点处的文件名一致,你当然可以为它进行其他的命名,但按惯例来说,我们一般使用feature.xml。它的内容会类似于下面的样子:
<?xml version="1.0" encoding="utf-8" ?>
<Feature  Title="ExpenseRequestTemplate" 
          Id
="8EB2BC09-79DB-444a-AAC7-3B9521562C72"
          Description
="This feature is created for the template of Expense Request." 
          Version
="1.0.0.0" 
          Scope
="Site" 
          DefaultResourceFile
="ipfscore"
          ReceiverAssembly
="Microsoft.Office.InfoPath.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
          ReceiverClass
="Microsoft.Office.InfoPath.Server.Administration.XsnFeatureReceiver"
          xmlns
="http://schemas.microsoft.com/sharepoint/">
  
  
<ElementManifests>
    
<ElementManifest Location="Elements.xml" />
    
<ElementFile Location="ExpenseRequestInit.xsn" />
    
<ElementFile Location="ExpenseRequestInitForm.dll" />
  
</ElementManifests>
  
<ActivationDependencies>
    
<ActivationDependency FeatureId="C88C4FF1-DBF5-4649-AD9F-C6C426EBCBF5"/>
  
</ActivationDependencies>

  
<Properties>
    
<Property Key="ExpenseRequestTemplate" Value="Expense Request Template" />
  
</Properties>
</Feature>
  其中的ActivationDepenencies的节点部分是确保Infopath Form Services在feature被激活之前处于可用的状态。
  ReceiverAssembly和ReceiverClass是确保Infopath Form Services在feature的install、uninstall、activate和deactivate过程中执行正确的操作。
  另外,如果你有不止一个的Infopath表单模板需要通过这个feature进行部署,你只要在ElementManifests节点中增加相应的文件即可。
  不要忘了在Feature节点中使用一个新的Id。

    Elements.xml:同样,这个文件的命名也需要跟feature.xml中定义的文件名保持一致,它的内容会类似于下面的样子:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  
<Module Name="XSN" Url="FormServerTemplates" RootWebOnly="TRUE">
    
<File Url="ExpenseRequestInit.xsn" Name="ExpenseRequestInit.xsn" Type="GhostableInLibrary" />
  
</Module>
</Elements>
这个文件的作用是为了让WSS的runtime为你的表单库提供正确的表单模板。

    solution.ddf: 终于到了最后一个文件了,马上就要大功告成了。这个文件只是为了我们稍后使用makecab时而定义的文件,它会为makecab传入一些必要的参数,告诉makecab应该如何创建wsp。它会有一些简单的语法,它的内容会类似于下面的样子:
;
.OPTION EXPLICIT     ; Generate errors 
.Set CabinetNameTemplate=ExpenseRequestTemplate.wsp
.set DiskDirectoryTemplate=CDROM ; All cabinets go in a single directory
.Set CompressionType=MSZIP;** All files are compressed in cabinet files
.Set UniqueFiles="ON"
.Set Cabinet=on
.Set DiskDirectory1=Package
.Set MaxDiskSize=1024000000
ExpenseRequestTemplate
\manifest.xml manifest.xml

"ExpenseRequestTemplate\feature.xml" "ExpenseRequestTemplate\feature.xml"
"ExpenseRequestTemplate\Elements.xml" "ExpenseRequestTemplate\Elements.xml"


"resources\ExpenseRequestInit.xsn" "ExpenseRequestTemplate\ExpenseRequestInit.xsn"
"bin\Debug\ExpenseRequestInitForm.dll" "ExpenseRequestTemplate\ExpenseRequestInitForm.dll"
ddf文件使用";"进行单行的注释,"."起始的行是一些选项的设定。
我有一点搞不太明白的是,Infopath表单的dll文件部署后是与xsn文件一起放在feature的目录下,而不是象工作流等类型的feature将dll放在gac目录中,奇怪。

当上述的几个文件全部准备好之后,我们就可以使用makecab进行打包了。
在命令行下执行:makecab /f solution.ddf

大功告成,我们最终需要的wsp文件终于生成好了,可以将它部署到Sharepoint站点中了。

小技巧:
可在注册表中添加如下键值,便可将Add Solution绑定到wsp文件的右键菜单中了:

[HKEY_CLASSES_ROOT\.wsp]
@="wspfile"

[HKEY_CLASSES_ROOT\wspfile\shell]
[HKEY_CLASSES_ROOT\wspfile\shell\Add Solution]
[HKEY_CLASSES_ROOT\wspfile\shell\Add Solution\command]
@="C:\\Program Files\\Common Files\\Microsoft Shared\\web server extensions\\12\\BIN\\stsadm.exe -o addsolution -filename \"%1\""

posted @ 2008-09-26 10:25  皇上爱累了  阅读(603)  评论(2)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3