自定义内容类型

时间:2012-06-26 16:06:16

标签: c# visual-studio-2010 sharepoint sharepoint-2010 sharepoint-designer

我在visual studio 2010中创建了自定义内容类型:

custom http://img204.imageshack.us/img204/439/customf.jpg

这里有我的自定义内容类型.... 我想在同一站点的子站点中使用此内容类型。 现在我有了这个:

http // XXXXX /........../ Forms / AllItems.aspx

我想在

中使用此内容类型

http // XXXXX / SUBSITE ..... / Forms / AllItems.aspx ...

在代码中,我将自定义内容类型与第一个文档库相关联,如下所示:

 <CustomAction
Id="SPTest.CustomMenuItem.ButtonClicked"
Location="CommandUI.Ribbon.ListView"
RegistrationId="{F9658A9F-3F04-48BD-A14A-9EBAF5DE9EE8}"
RegistrationType="List"
>

其中RegistrationId是文档库网站的ID,但是当我在这个RegistrationId中放入子网站文档库的ID时......没有任何反应......

另一个问题:当我选择此文档库中的项目时,将显示“文档”选项卡....是否有某种方式可以显示PATOne Rule Engine而不是文档选项卡???

2 个答案:

答案 0 :(得分:1)

这是“自定义操作”,而不是“自定义内容类型”。提示:内容类型将包含“ContentType”元素。它看起来像:

<ContentType ID="0x01AB"
     Name="MyCustomContentType"
     Group="MyCustomContentTypeGroup"
     Description="Customized Content Type"
     Version="0">
   <FieldRefs>
    <FieldRef ID="{8c06beca-0777-48f7-91c7-6da68bc07b69}"
     Name="Created"
     DisplayName="Field1" />
    <FieldRef ID="{1df5e554-ec7e-46a6-901d-d85a3881cb18}"
     Name="Author"
     DisplayName="Field2" />
   </FieldRefs>
</ContentType>

此外,如果要针对内容类型进行注册,则RegistrationId不应该是guid。如果针对列表注册,则RegistrationId应该是列表的类型ID,例如(对于站点中的文档库为101),或者可能是特定列表的GUID(在这种情况下,该操作仅适用于该列表)。我没试过这最后一个,但怀疑它有用。 (修改:它被描述为在this discussion的底部以这种方式工作)

根据guid的内容,您可能已经为特定列表注册了自定义操作,但子网站中的列表将具有不同的ID,因此自定义操作注册将不适用于它。

简而言之,您可以将自定义操作添加到:

  • 一个特定的列表,我认为你已经完成了。
  • 网站/子网站中给定类​​型的所有列表
  • A content type然后您在这些列表中使用。 (我没试过)

要注册内容类型,我希望注册看起来像:

<CustomAction 
    Id="SPTest.CustomMenuItem.ButtonClicked"              
    Location="CommandUI.Ribbon.ListView"
    RegistrationType="ContentType"
    RegistrationId="0x01AB"

请注意RegistrationType和RegistrationId

答案 1 :(得分:0)

这是我的内容类型

<?xml version="1.0" encoding="utf-8"?>
 <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="SPTest.CustomMenuItem.ButtonClicked"
Location="CommandUI.Ribbon.ListView"
RegistrationId="{F9658A9F-3F04-48BD-A14A-9EBAF5DE9EE8}"
RegistrationType="List"
>
<CommandUIExtension>
  <CommandUIDefinitions>
    <CommandUIDefinition
      Location="Ribbon.Tabs._children">
      <Tab
        Id="Ribbon.PATOneRule"
        Title="PATOne Rule Engine"
        Sequence="501">
        <Scaling
          Id="Ribbon.PATOneRule.Scaling">
          <MaxSize
            Id="Ribbon.PATOneRule.MaxSize"
            GroupId="Ribbon.PATOneRule.PATOneRuleGroup"
            Size="OneLargeTwoMedium"/>
          <Scale
            Id="Ribbon.PATOneRule.Scaling.PATOneRuleScaling"
            GroupId="Ribbon.PATOneRule.PATOneRuleGroup"
            Size="OneLargeTwoMedium" />
        </Scaling>
        <Groups Id="Ribbon.PATOneRule.Groups">
          <Group
            Id="Ribbon.PATOneRule.PATOneRuleGroup"
            Description="Workflow Rules"
            Title="Workflow Group"
            Sequence="52"
            Template="Ribbon.Templates.CustomTemplateExample">
            <Controls Id="Ribbon.PATOneRule.PATOneRuleGroup.Controls">
              <Button
                Id="Ribbon.PATOneRule.PATOneRuleGroup.NewWorkflow"
                Image32by32="/PublishingImages/_t/new_jpg.jpg"
                Command="PATOneRule.NewWorkflow"
                Sequence="15"
                Description="Create New Workflow"
                LabelText="New Workflow"
                TemplateAlias="cust1"/>
              <Button
                Id="Ribbon.PATOneRule.PATOneRuleGroup.RunWorkflow"
                Image32by32="/PublishingImages/_t/play_jpg.jpg"
                Command="PATOneRule.RunWorkflow"
                Sequence="15"
                Description="Run Selected Workflow"
                LabelText="Run Workflow"
                TemplateAlias="cust2"/>
              <Button
               Id="Ribbon.PATOneRule.PATOneRuleGroup.EditWorkflow"
               Image32by32="/PublishingImages/_t/edit_jpg.jpg"
               Command="PATOneRule.EditWorkflow"
               Sequence="15"
               Description="Edit Selected Workflow"
               LabelText="Edit Workflow"
               TemplateAlias="cust3"/>
            </Controls>
          </Group>
        </Groups>
      </Tab>
    </CommandUIDefinition>
    <CommandUIDefinition Location="Ribbon.Templates._children">
      <GroupTemplate Id="Ribbon.Templates.CustomTemplateExample">
        <Layout
          Title="OneLargeTwoMedium"
          LayoutTitle="OneLargeTwoMedium">
          <Section Alignment="Top" Type="OneRow">
            <Row>
              <ControlRef DisplayMode="Large" TemplateAlias="cust1" />
              <ControlRef DisplayMode="Large" TemplateAlias="cust3" />
              <ControlRef DisplayMode="Large" TemplateAlias="cust2" />
            </Row>
          </Section>
        </Layout>
      </GroupTemplate>
    </CommandUIDefinition>
  </CommandUIDefinitions>
  <CommandUIHandlers>
    <CommandUIHandler
      Command="PATOneRule.NewWorkflow"
      CommandAction="javascript:__doPostBack('NewWorkflow', '')" />
    <CommandUIHandler
     Command="PATOneRule.EditWorkflow"
     CommandAction="javascript: 
     function getId() { 
       var ctx = SP.ClientContext.get_current();
       var selectedItems = SP.ListOperation.Selection.getSelectedItems(ctx);
       var key;
       var itemsSelected;
       for (key in selectedItems) {
       itemsSelected = itemsSelected + ', ' + selectedItems[key].id;
      } 
      __doPostBack('EditWorkflow',itemsSelected); 
     }
     getId();"
     EnabledScript="javascript:
     function singleEnable() { 
       var items = 
       SP.ListOperation.Selection.getSelectedItems(); 
       var ci = CountDictionary(items); 
       return (ci == 1); 
     } 
     singleEnable();"
     />
    <CommandUIHandler
    Command="PATOneRule.RunWorkflow"
    CommandAction="javascript: 
     function getId() { 
       var ctx = SP.ClientContext.get_current();
       var selectedItems = SP.ListOperation.Selection.getSelectedItems(ctx);
       var key;
       var itemsSelected;
       for (key in selectedItems) {
       itemsSelected = itemsSelected + ', ' + selectedItems[key].id;
      } 
      __doPostBack('RunWorkflow',itemsSelected); 
     }
     getId();"
    EnabledScript="javascript:
     function singleEnable() { 
       var items = 
       SP.ListOperation.Selection.getSelectedItems(); 
       var ci = CountDictionary(items); 
       return (ci>0); 
     } 
     singleEnable();"
     />
  </CommandUIHandlers>
</CommandUIExtension>