MOSS 2010 Content Type(内容类型)开发中的一个问题及其解决方法

内容类型是SharePoint中一个很重要的功能,简单地说,它使得我们可以定制列表或者文档库的项目模板。关于这个方面,我以前也写过一些文章介绍,请参考

http://zzk.cnblogs.com/s?w=blog%3Achenxizhang%20%E5%86%85%E5%AE%B9%E7%B1%BB%E5%9E%8B

 

 

今天要讲的一个问题,是我们在项目中遇到的,虽然不大,但却是困扰了很久,而且百思不得其解(以前在MOSS 2007的时候却没有这个问题)。

这个问题最近与微软中国这边有关的朋友交流才得到结论,有点让人哭笑不得的。不过,还是要谢谢

 

范例是一个简单的Solution。我大致介绍一下里面的内容

1. 基于Item这种基类型,创建了一个ContentType,定义了一个特殊的Field,并且定义了特殊的New,Edit,Display页面

我们的目的是希望用户使用该类型类型的话,新建,编辑和查看的页面都是我们定制过的

 

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <!-- Parent ContentType: Item (0x01) -->
  <ContentType ID="0x0100b05ebf7c0a1b48c5aa4aae0a9a8b1067"
               Name="SharePointProjectSample - SampleContentType"
               Group="Custom Content Types"
               Description="My Content Type"
               Inherits="TRUE"
               Version="0">
    <FieldRefs>
      <FieldRef ID="{9da97a8a-1da5-4a77-98d3-4bc10456e700}" Name="Comments" DisplayName="Comments"/>
      <FieldRef ID="{F7D24529-1883-4686-A6DA-6BA772D6CE7D}" Name="Test" DisplayName="Test"/>
    </FieldRefs>
    <XmlDocuments>
      <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
        <FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
          <New>
            _layouts/SharePointProjectSample/New.aspx
          </New>
          <Edit>
            _layouts/SharePointProjectSample/Edit.aspx
          </Edit>
          <Display>
            _layouts/SharePointProjectSample/Display.aspx
          </Display>
        </FormUrls>
      </XmlDocument>
    </XmlDocuments>
  </ContentType>
</Elements>

2. 基于上面这个ContentType,我创建了一个ListDefinition

3. 基于上面这个ListDefinition,我创建了一个ListInstance

image

解决方案部署,没有发现任何问题。我们可以看到一个新的列表创建起来了。

clip_image001

但是,点击”Add new item”的时候,却会发现如下的错误

clip_image002

我们使用IE 9自带的Developer Tools进行调试看看

clip_image002[5]

我们可以看到,其实它确实是想去打开我们那个New.aspx,但我看那个地址编码似乎是有问题的,前面有一串%20,这个应该是空格的意思

那么,这是为什么呢?其实是因为我们在定义ContentType的时候,那个xml文件中有空格。我们将它修改成下面这样子(请注意粗体部分)

 

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <!-- Parent ContentType: Item (0x01) -->
  <ContentType ID="0x0100b05ebf7c0a1b48c5aa4aae0a9a8b1067"
               Name="SharePointProjectSample - SampleContentType"
               Group="Custom Content Types"
               Description="My Content Type"
               Inherits="TRUE"
               Version="0">
    <FieldRefs>
      <FieldRef ID="{9da97a8a-1da5-4a77-98d3-4bc10456e700}" Name="Comments" DisplayName="Comments"/>
      <FieldRef ID="{F7D24529-1883-4686-A6DA-6BA772D6CE7D}" Name="Test" DisplayName="Test"/>
    </FieldRefs>
    <XmlDocuments>
      <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
        <FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
          <New>_layouts/SharePointProjectSample/New.aspx</New>
          <Edit>_layouts/SharePointProjectSample/Edit.aspx</Edit>
          <Display>_layouts/SharePointProjectSample/Display.aspx</Display>
        </FormUrls>
      </XmlDocument>
    </XmlDocuments>
  </ContentType>
</Elements>
重新部署,页面出来了,整个世界清静了
 
【备注】个人觉得这个问题应该在产品级别修正掉,而不是给开发人员这种强制性的要求。其实不难的,不是吗,读取那个地址字符串之后,调用trim方法即可。呵呵
 
目前而言,大家还是稍加注意吧,不要有空格
 
 
 
 
posted @ 2010-11-03 17:39  陈希章  阅读(2107)  评论(0编辑  收藏  举报