如何在SharePoint Blog中显示附件(Attachement file)
参考了一个博客(http://www.pampigt.se/?p=69),其中自己也下了不少功夫,主要是对SharePoint Designer中Data view的使用方法不熟悉,走了些弯路,但终于还是搞定了。贡献给大家,应该也算是个原创吧。
1. 在NewPost画面增加Attach File按钮。
- 修改文件:C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\SiteTemplates\Blog\Lists\Posts\schema.xml。
将以下内容
代码<Forms>
<Form Type="DisplayForm" Url="ViewPost.aspx" WebPartZoneID="Main" />
<Form Type="EditForm" Url="EditPost.aspx" ToolbarTemplate="BlogEditFormToolBar" Template="BlogForm" WebPartZoneID="Main" />
<Form Type="NewForm" Url="NewPost.aspx" ToolbarTemplate="BlogNewFormToolBar" Template="BlogForm" WebPartZoneID="Main" />
</Forms>
代码<Forms>
<Form Type="DisplayForm" Url="ViewPost.aspx" WebPartZoneID="Main" />
<Form Type="EditForm" Url="EditPost.aspx" WebPartZoneID="Main" />
<Form Type="NewForm" Url="NewPost.aspx" WebPartZoneID="Main" />
</Forms> - 修改Post.aspx的View,显示附件。
打开Post.aspx,编辑该页面。在当前的View中,选择现实Attachments。这时,只会显示一个附件的图标,表示是否有附件,但是文件的链接不能显示。
2. 修改Post.aspx,显示附件的链接。
- 用SharePoint Designer 2007,打开Post.aspx。
- 选中Post Webpart(它应该是显示There are no posts in this categray.),点击右键执行“Covert to XSLT data view”。
转换后会有一个错误,发生在以下语句:
<xsl:when test="=@Author">
改为以下即可。
<xsl:when test="@Author"> - 转换完成后,点击菜单:Data View->Parameters...。增加一个新的Parameter。如下图:
- 点击菜单:Data View->Filter...。增加一个新的Filter。如下图:
- 编辑Post.aspx的最新Code。找到以下代码:
代码<xsl:when test="@Attachments=''"></xsl:when>
<xsl:otherwise>Attachments:
<xsl:if test="not (@Attachments=0)"><img border="0" src="{$HttpVDir}/_layouts/images/attach.gif" />
</xsl:if>
</xsl:otherwise> -
代码<xsl:when test="@Attachments=''"></xsl:when>
<xsl:otherwise>Attachments:
<xsl:if test="not (@Attachments=0)">
<xsl:element name="SharePoint:AttachmentsField">
<xsl:attribute name="runat">server</xsl:attribute>
<xsl:attribute name="ListId">{AC915FEE-C3BE-4102-8D84-75A384A327A2}</xsl:attribute>
<xsl:attribute name="FieldName">Attachments</xsl:attribute>
<xsl:attribute name="ControlMode">Display</xsl:attribute>
<xsl:attribute name="Visible">true</xsl:attribute>
</xsl:element>
</xsl:if>
</xsl:otherwise>注意:ListId要替换为自己网站内的ListId。
- 保存Post.aspx。
至此,大功告成。重新在IE下打开Post.aspx,将会看到原来附件图标不见了,取而代之的是附件的链接。有多个附件时,将以多行显示。