我想在运行时更改文档库中的文档图标。应根据代码中的某些条件更改图标。文件的扩展名是什么(txt,doc,pdf等等)没有区别。目前我使用HTTP模块来解析服务器响应并在运行时更改图标。但是,此解决方案不可靠,因为页面HTML标记可能会更改,不同的视图具有不同的行为,并且SharePoint 2010中的注册HTTP模块存在问题。 是否有任何API或任何其他可靠的方法在运行时更改文档的图标?
我将不胜感激任何帮助。 先谢谢, -Petro
答案 0 :(得分:1)
以下是Sharepoint 2010标准DocIcon Field的架构(非常庞大):
<Field ID="{081c6e4c-5c14-4f20-b23e-1a71ceb6a67c}" Type="Computed" ReadOnly="TRUE" Name="DocIcon" DisplayName="Тип" TextOnly="TRUE" ClassInfo="Icon" AuthoringInfo="(значок связи с документом)" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="DocIcon" FromBaseType="TRUE">
<FieldRefs>
<FieldRef Name="File_x0020_Type" />
<FieldRef Name="FSObjType" />
<FieldRef Name="FileRef" />
<FieldRef Name="FileLeafRef" />
<FieldRef Name="HTML_x0020_File_x0020_Type" />
<FieldRef Name="PermMask" />
<FieldRef Name="CheckoutUser" ShowField="Title" />
<FieldRef Name="IsCheckedoutToLocal" />
<FieldRef Name="ServerUrl" />
<FieldRef Name="IconOverlay" />
</FieldRefs>
<DisplayPattern>
<SetVar Name="DocIconImg">
<SetVar Name="DocIconAltText">
<IfEqual>
<Expr1>
<LookupColumn Name="FSObjType" />
</Expr1>
<Expr2>1</Expr2>
<Then>
<IfSubString>
<Expr1>0x0120D5</Expr1>
<Expr2>
<Column Name="ContentTypeId" />
</Expr2>
<Then>
<HTML>Коллекция документов: </HTML>
<LookupColumn Name="FileLeafRef" HTMLEncode="TRUE" />
</Then>
<Else>
<HTML>Папка: </HTML>
<LookupColumn Name="FileLeafRef" HTMLEncode="TRUE" />
</Else>
</IfSubString>
</Then>
<Else>
<LookupColumn Name="FileLeafRef" HTMLEncode="TRUE" />
</Else>
</IfEqual>
</SetVar>
<SetVar Name="DocIconFileName">
<IfEqual>
<Expr1>
<Column Name="IconOverlay" />
</Expr1>
<Expr2 />
<Then>
<IfEqual>
<Expr1>
<LookupColumn Name="FSObjType" />
</Expr1>
<Expr2>1</Expr2>
<Then>
<IfEqual>
<Expr1>
<Column Name="HTML_x0020_File_x0020_Type" />
<HTML>|</HTML>
<Column Name="File_x0020_Type" />
</Expr1>
<Expr2>
<HTML>|</HTML>
</Expr2>
<Then>
<HTML>folder.gif</HTML>
</Then>
<Else>
<SetVar Name="FolderIconFromMap">
<MapToIcon>
<Column Name="HTML_x0020_File_x0020_Type" />
<HTML>|</HTML>
<Column Name="File_x0020_Type" />
</MapToIcon>
</SetVar>
<IfEqual>
<Expr1>
<GetVar Name="FolderIconFromMap" />
</Expr1>
<Expr2>
<MapToIcon />
</Expr2>
<Then>
<HTML>folder.gif</HTML>
</Then>
<Else>
<GetVar Name="FolderIconFromMap" />
</Else>
</IfEqual>
</Else>
</IfEqual>
</Then>
<Else>
<MapToIcon>
<Column Name="HTML_x0020_File_x0020_Type" />
<HTML>|</HTML>
<Column Name="File_x0020_Type" />
</MapToIcon>
</Else>
</IfEqual>
</Then>
<Else>
<MapToIcon>
<Column Name="IconOverlay" />
</MapToIcon>
</Else>
</IfEqual>
</SetVar>
<HTML><![CDATA[<img border="0" alt="]]></HTML>
<GetVar Name="DocIconAltText" />
<HTML><![CDATA[" title="]]></HTML>
<GetVar Name="DocIconAltText" />
<HTML><![CDATA[" src="/_layouts/images/]]></HTML>
<GetVar Name="DocIconFileName" />
<HTML><![CDATA[" />]]></HTML>
</SetVar>
<SetVar Name="DocIconOverlayImg">
<IfEqual>
<Expr1>
<Column Name="IconOverlay" />
</Expr1>
<Expr2 />
<Then>
<IfEqual>
<Expr1>
<Column Name="CheckoutUser" />
</Expr1>
<Expr2 />
<Else>
<SetVar Name="DocIconOverlayAltText">
<LookupColumn Name="FileLeafRef" HTMLEncode="TRUE" />
<HTML><![CDATA[ Кем извлечено: ]]></HTML>
<LookupColumn Name="CheckoutUser" ShowField="Title" HTMLEncode="TRUE" />
</SetVar>
<HTML><![CDATA[<img class="ms-vb-icon-overlay" alt="]]></HTML>
<GetVar Name="DocIconOverlayAltText" />
<HTML><![CDATA[" title="]]></HTML>
<GetVar Name="DocIconOverlayAltText" />
<HTML><![CDATA[" src="/_layouts/images/checkoutoverlay.gif" />]]></HTML>
</Else>
</IfEqual>
</Then>
<Else>
<HTML><![CDATA[<img class="ms-vb-icon-overlay" alt="*" src="/_layouts/images/]]></HTML>
<MapToOverlay>
<Column Name="IconOverlay" />
</MapToOverlay>
<HTML><![CDATA[" />]]></HTML>
</Else>
</IfEqual>
</SetVar>
<IfEqual>
<Expr1>
<LookupColumn Name="FSObjType" />
</Expr1>
<Expr2>1</Expr2>
<Then>
<FieldSwitch>
<Expr>
<GetVar Name="RecursiveView" />
</Expr>
<Case Value="1">
<GetVar Name="DocIconImg" />
<GetVar Name="DocIconOverlayImg" />
</Case>
<Default>
<SetVar Name="UnencodedFilterLink">
<SetVar Name="RootFolder">
<HTML>/</HTML>
<LookupColumn Name="FileRef" />
</SetVar>
<SetVar Name="SkipHost">1</SetVar>
<SetVar Name="FolderCTID">
<FieldSwitch>
<Expr>
<ListProperty Select="EnableContentTypes" />
</Expr>
<Case Value="1">
<Column Name="ContentTypeId" />
</Case>
</FieldSwitch>
</SetVar>
<FilterLink Default="" Paged="FALSE" />
</SetVar>
<FieldSwitch>
<Expr>
<GetVar Name="FileDialog" />
</Expr>
<Case Value="1">
<GetVar Name="DocIconImg" />
<GetVar Name="DocIconOverlayImg" />
</Case>
<Default>
<HTML><![CDATA[<a href="]]></HTML>
<GetVar Name="UnencodedFilterLink" HTMLEncode="TRUE" />
<HTML><![CDATA[" onmousedown="javascript:VerifyFolderHref(this,event, ']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<GetVar Name="UnencodedFilterLink" />
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<ServerProperty Select="HtmlTrProgId">
<Column Name="File_x0020_Type" />
</ServerProperty>
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<ListProperty Select="DefaultItemOpen" />
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<MapToControl>
<Column Name="HTML_x0020_File_x0020_Type" />
<HTML>|</HTML>
<Column Name="File_x0020_Type" />
</MapToControl>
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<Column Name="HTML_x0020_File_x0020_Type" />
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<ServerProperty Select="GetServerFileRedirect">
<Field Name="ServerUrl" />
<HTML>|</HTML>
<Column Name="HTML_x0020_File_x0020_Type" />
</ServerProperty>
</ScriptQuote>
<HTML><![CDATA[')"]]></HTML>
<HTML><![CDATA[" onclick="return HandleFolder(this,event, ']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<GetVar Name="UnencodedFilterLink" />
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<ServerProperty Select="HtmlTransform" />
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<ServerProperty Select="HtmlTrAcceptType">
<Column Name="File_x0020_Type" />
</ServerProperty>
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<ServerProperty Select="HtmlTrHandleUrl">
<Column Name="File_x0020_Type" />
</ServerProperty>
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<ServerProperty Select="HtmlTrProgId">
<Column Name="File_x0020_Type" />
</ServerProperty>
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<ListProperty Select="DefaultItemOpen" />
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<MapToControl>
<Column Name="HTML_x0020_File_x0020_Type" />
<HTML>|</HTML>
<Column Name="File_x0020_Type" />
</MapToControl>
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<Column Name="HTML_x0020_File_x0020_Type" />
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<ServerProperty Select="GetServerFileRedirect">
<Field Name="ServerUrl" />
<HTML>|</HTML>
<Column Name="HTML_x0020_File_x0020_Type" />
</ServerProperty>
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<Column Name="CheckoutUser" />
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<UserID AllowAnonymous="TRUE" />
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<ListProperty Select="ForceCheckout" />
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<Field Name="IsCheckedoutToLocal" />
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<Field Name="PermMask" />
</ScriptQuote>
<HTML><![CDATA[');">]]></HTML>
<GetVar Name="DocIconImg" />
<GetVar Name="DocIconOverlayImg" />
<HTML><![CDATA[</a>]]></HTML>
</Default>
</FieldSwitch>
</Default>
</FieldSwitch>
</Then>
<Else>
<HTML><![CDATA[<a href="]]></HTML>
<Field Name="ServerUrl" URLEncodeAsURL="TRUE" />
<HTML><![CDATA[" onclick="return DispEx(this,event,']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<ServerProperty Select="HtmlTransform" />
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<ServerProperty Select="HtmlTrAcceptType">
<Column Name="File_x0020_Type" />
</ServerProperty>
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<ServerProperty Select="HtmlTrHandleUrl">
<Column Name="File_x0020_Type" />
</ServerProperty>
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<ServerProperty Select="HtmlTrProgId">
<Column Name="File_x0020_Type" />
</ServerProperty>
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<ListProperty Select="DefaultItemOpen" />
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<MapToControl>
<Column Name="HTML_x0020_File_x0020_Type" />
<HTML>|</HTML>
<Column Name="File_x0020_Type" />
</MapToControl>
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<Column Name="HTML_x0020_File_x0020_Type" />
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<ServerProperty Select="GetServerFileRedirect">
<Field Name="ServerUrl" />
<HTML>|</HTML>
<Column Name="HTML_x0020_File_x0020_Type" />
</ServerProperty>
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<Column Name="CheckoutUser" />
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<UserID AllowAnonymous="TRUE" />
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<ListProperty Select="ForceCheckout" />
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<Field Name="IsCheckedoutToLocal" />
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<Field Name="PermMask" />
</ScriptQuote>
<HTML><![CDATA[')">]]></HTML>
<GetVar Name="DocIconImg" />
<GetVar Name="DocIconOverlayImg" />
<HTML><![CDATA[</a>]]></HTML>
</Else>
</IfEqual>
</DisplayPattern>
</Field>
您可以获取要修改图标的库的DocIcon字段(通过代码)并修改其架构。正如您所看到的,部分中有很多XSLT,但它非常简单,可以添加新模式而不会出现大问题(旧的模式可以删除)。另一种方法是创建自己的自定义字段类型,并使用它而不是标准字段来显示图标。