今天要講的一個(gè)問題,是我們?cè)陧?xiàng)目中遇到的,雖然不大,但卻是困擾了很久,而且百思不得其解(以前在MOSS 2007的時(shí)候卻沒有這個(gè)問題)。
這個(gè)問題最近與微軟中國這邊有關(guān)的朋友交流才得到結(jié)論,有點(diǎn)讓人哭笑不得的。不過,還是要謝謝
范例是一個(gè)簡單的Solution。我大致介紹一下里面的內(nèi)容
1. 基于Item這種基類型,創(chuàng)建了一個(gè)ContentType,定義了一個(gè)特殊的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. 基于上面這個(gè)ContentType,我創(chuàng)建了一個(gè)ListDefinition
3. 基于上面這個(gè)ListDefinition,我創(chuàng)建了一個(gè)ListInstance
解決方案部署,沒有發(fā)現(xiàn)任何問題。我們可以看到一個(gè)新的列表創(chuàng)建起來了。
但是,點(diǎn)擊”Add new item”的時(shí)候,卻會(huì)發(fā)現(xiàn)如下的錯(cuò)誤
我們使用IE 9自帶的Developer Tools進(jìn)行調(diào)試看看
我們可以看到,其實(shí)它確實(shí)是想去打開我們那個(gè)New.aspx,但我看那個(gè)地址編碼似乎是有問題的,前面有一串%20,這個(gè)應(yīng)該是空格的意思
那么,這是為什么呢?其實(shí)是因?yàn)槲覀冊(cè)诙xContentType的時(shí)候,那個(gè)xml文件中有空格。我們將它修改成下面這樣子(請(qǐng)注意粗體部分)
<?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>
重新部署,頁面出來了,整個(gè)世界清靜了
【備注】個(gè)人覺得這個(gè)問題應(yīng)該在產(chǎn)品級(jí)別修正掉,而不是給開發(fā)人員這種強(qiáng)制性的要求。其實(shí)不難的,不是嗎,讀取那個(gè)地址字符串之后,調(diào)用trim方法即可。呵呵,目前而言,大家還是稍加注意吧,不要有空格