今天要講的一個問題,是我們在項目中遇到的,雖然不大,但卻是困擾了很久,而且百思不得其解(以前在MOSS 2007的時候卻沒有這個問題)。
這個問題最近與微軟中國這邊有關的朋友交流才得到結論,有點讓人哭笑不得的。不過,還是要謝謝
范例是一個簡單的Solution。我大致介紹一下里面的內容
1. 基于Item這種基類型,創(chuàng)建了一個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,我創(chuàng)建了一個ListDefinition
3. 基于上面這個ListDefinition,我創(chuàng)建了一個ListInstance
解決方案部署,沒有發(fā)現(xiàn)任何問題。我們可以看到一個新的列表創(chuàng)建起來了。
但是,點擊”Add new item”的時候,卻會發(fā)現(xiàn)如下的錯誤
我們使用IE 9自帶的Developer Tools進行調試看看
我們可以看到,其實它確實是想去打開我們那個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>
重新部署,頁面出來了,整個世界清靜了
【備注】個人覺得這個問題應該在產(chǎn)品級別修正掉,而不是給開發(fā)人員這種強制性的要求。其實不難的,不是嗎,讀取那個地址字符串之后,調用trim方法即可。呵呵,目前而言,大家還是稍加注意吧,不要有空格