Adding Attachments to SharePoint blogs

While SharePoint 2007 does offer a blog-template, this is actually quite minimalistic. Even though you can usually add attachments to every list item in sharepoint, this is not possible for blog posts.

Well, actually, attachments are enabled for blog posts, and if you’re using an editor such as Windows Live Writer all images and files are being added as attachments to the current post. But this just isn’t possible if you’re stuck with the web-editor for writing new posts.

So I did some digging on what’s needed to get SharePoint to offer attachments for blog posts.

First of all you should be aware, that you’re going to modify some files dear and near to SharePoint – this might not always be the recommended way 🙂

OK, let’s get started. Since we already noticed that attachments are enabled on the list of posts, we somehow need to get this darn button in the toolbar to appear.

Since the blogging feature is built-in into SharePoint it’s view definition is found in the DefaultTemplates.ascx within the %CommonProgramFiles%\Microsoft Shared\Web Server Extensions\12\Template\ControlTemplates. Within this file are a whole lot of Rendering-Templates defined. Based on the existing BlogForm Template I created my own Template called BlogFormExt.

<SharePoint:RenderingTemplate ID="BlogFormExt" runat="server">
    <Template>
        <SPAN id='part1'>
            <SharePoint:InformationBar runat="server"/>
            <wssuc:ToolBar CssClass="ms-formtoolbar" id="toolBarTbltop" RightButtonSeparator="&nbsp;" runat="server">
                    <Template_RightButtons>
                        <SharePoint:SaveAsDraftButton Text="<%$Resources:wss,tb_saveasdraft%>" runat="server"/>
                        <SharePoint:PublishButton Text="<%$Resources:wss,tb_publish%>" runat="server"/>
                        <SharePoint:GoBackButton runat="server"/>
                    </Template_RightButtons>
            </wssuc:ToolBar>
            <SharePoint:FormToolBar runat="server"/>
            <p><a href="javascript:UploadAttachment();">Attach Me!</a></p>
            <TABLE class="ms-formtable" style="margin-top: 8px;" border=0 cellpadding=0 cellspacing=0 width=100%>
            <SharePoint:ChangeContentType runat="server"/>
            <SharePoint:FolderFormFields runat="server"/>
            <SharePoint:ListFieldIterator runat="server"/>
            <SharePoint:ApprovalStatus runat="server"/>
            <SharePoint:FormComponent TemplateName="AttachmentRows" runat="server"/>
            </TABLE>
            <table cellpadding=0 cellspacing=0 width=100% style="margin-top: 10px;"><tr><td class="ms-formline"><IMG SRC="/_layouts/images/blank.gif" width=1 height=1 alt=""></td></tr></table>
            <TABLE cellpadding=0 cellspacing=0 width=100% style="padding-top: 7px"><tr><td width=100%>
            <SharePoint:ItemHiddenVersion runat="server"/>
            <wssuc:ToolBar CssClass="ms-formtoolbar" id="toolBarTbl" RightButtonSeparator="&nbsp;" runat="server">
                    <Template_Buttons>
                        <SharePoint:InitContentType runat="server"/>
                        <SharePoint:CreatedModifiedInfo runat="server"/>
                    </Template_Buttons>
                    <Template_RightButtons>
                        <SharePoint:SaveAsDraftButton Text="<%$Resources:wss,tb_saveasdraft%>" runat="server"/>
                        <SharePoint:PublishButton Text="<%$Resources:wss,tb_publish%>" runat="server"/>
                        <SharePoint:GoBackButton runat="server"/>
                    </Template_RightButtons>
            </wssuc:ToolBar>
            </td></tr></TABLE>
        </SPAN>
        <SharePoint:AttachmentUpload runat="server"/>
    </Template>
</SharePoint:RenderingTemplate>

Important are the two highligthed lines. The first line adds a link to display a dialog to upload an attachment, the orher line adds the actual code for the dialog and stuff.

OK, so now we habe our new layout in place, that allows us to add attachments to new posts. Next we need to alter our blog to make use of this new template definition.

So using SharePoint-Designer open up the blog and navigate got the posts list. Open up the NewPost.aspx and find the webpart-element in the code view. There should be a line like

<TemplateName xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">BlogForm</TemplateName>

which you wand to edit to

<TemplateName xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">BlogFormExt</TemplateName>

This will use our new template-definition instead of the build-in template view.

This is basically all you need to do – well you also might want to edit the EditPost.aspx to use a template which enables the upload of new attachments; but I leave that to you.

Oh – one final note: this enables uploading attachments to a blog-post, but the attachments are not automatically displayed for e.g. as a list of items in the end of the post. You will have to add the links to the attachments in your post manually!.

Leave a Comment.