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">
        <SPAN id='part1'>
            <SharePoint:InformationBar runat="server"/>
            <wssuc:ToolBar CssClass="ms-formtoolbar" id="toolBarTbltop" RightButtonSeparator="&nbsp;" runat="server">
                        <SharePoint:SaveAsDraftButton Text="<%$Resources:wss,tb_saveasdraft%>" runat="server"/>
                        <SharePoint:PublishButton Text="<%$Resources:wss,tb_publish%>" runat="server"/>
                        <SharePoint:GoBackButton runat="server"/>
            <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 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">
                        <SharePoint:InitContentType runat="server"/>
                        <SharePoint:CreatedModifiedInfo runat="server"/>
                        <SharePoint:SaveAsDraftButton Text="<%$Resources:wss,tb_saveasdraft%>" runat="server"/>
                        <SharePoint:PublishButton Text="<%$Resources:wss,tb_publish%>" runat="server"/>
                        <SharePoint:GoBackButton runat="server"/>
        <SharePoint:AttachmentUpload runat="server"/>

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="">BlogForm</TemplateName>

which you wand to edit to

<TemplateName xmlns="">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.