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!.

Strange behaviors in SharePoint deployment

Today I had some really strange experiences while deploying some SharePoint application using a custom build WSP file.

First, I tried to re-deploy an existing solution, but that didn’t seem to succed. At least my SharePoint site replied with a “Service unavailable” notice. So I though, I should retract the solution – maybe someting in my updated solution broke my SharePoint site.

So doing a

stsadm –o retractsolution –name myapp.wsp –allcontenturls –immediate

also just failed on me. So next I was stuck. I couldn’t neither delete the solution nor retry to retract the solution because everytime I got the message, that another job is currently retracting this solution. This is why I couldn’t do anything at the moment. But what now? It didn’t seem like the was any other job running.

So I gathered a list of all running deployments using

stsadm –o enumdeployments

and then

stsadm –o canceldeployment –id

to actually cancel the running deployment. After that I could issue

stsadm –o deletesolution –name myapp.wsp –force

This actually remove the solution – but I had to find, that this wasn’t the cause for my “service unavailable”. So all this for nothing!

The strange thing about that is, that only one out of a dozen websites was not working. Then it strike me – looking at the IIS admin I found, that the app-pool associated with this SharePoint site was stopped – restarting the app-pool solved my “service unavailable” immediately.

Chuck Norris and SharePoint 2010

Top ten facts about Chuck Norris and SharePoint 2010:

  1. Chuck Norris never starts an Approval workflow in SharePoint. Chuck doesn’t need approval.
  2. Chuck Norris isn’t afraid to customize, one look and SharePoint runs at peak performance.
  3. Putting Chuck Norris in the SharePoint Visitors group is futile. Chuck always has Full Control.
  4. Chuck Norris doesn’t have a SharePoint Disaster Recovery Plan. He doesn’t recover data, only hostages.
  5. Chuck does not subscribe to Alerts. He knows what is happening before it happens.
  6. Chuck Norris IS the Governance Plan.
  7. In SharePoint 2010, the Farm Administrators group is being renamed to ‘Chuck’s Group’.
  8. Chuck Norris never get’s unexpected errors with SharePoint because he is always ready for everything.
  9. Chuck Norris doesn’t prepare for SharePoint 2010. SharePoint 2010 prepares for him.
  10. SharePoint 2010 was a Chuck Norris idea.

chucknorris