Home > Blogs > Eric Shupps | The SharePoint Cowboy > Posts > Creating Permalinks for SharePoint Blog Post Items
 
Eric Shupps eshupps The SharePoint Cowboy is the founder and President of BinaryWave, a leading provider of operational intelligence solutions for Microsoft SharePoint. Eric Shupps eshupps The SharePoint Cowboy has worked with SharePoint Products and Technologies since 2001 as a consultant, administrator, architect, developer and trainer. he is an advisory committee member of the Dallas/Ft. Worth SharePoint Community group and participating member of user groups throughout the United Kingdom. Eric Shupps eshupps The SharePoint Cowboy has authored numerous articles on SharePoint, speaks at user group meetings and conferences around the world, and publishes a popular SharePoint blog at http://www.sharepointcowboy.com. Presentations by Eric Shupps eshupps The SharePoint Cowboy Webinar - Migrating Legacy On Premise Solutions to SharePoint Online and Windows Azure featuring Eric Shupps Who are you and what do you want - Working with OAuth in SharePoint 2013 SharePoint is Talking Are You Listening? Eric Shupps SharePoint 2013 Performance Enhancements Taking Advantage of the SharePoint 2013 REST API Eric Shupps on Improving Performance with New Features in SharePoint 2013 SharePoint 2013 New and Improved Migrating Legacy On Premise Solutions to SharePoint Online and Windows Azure Eric Shupps Presents SharePoint 2013 Real World Help Desk App End to End Windows Azure Apps for SharePoint 2013 Eric Shupps Demonstrates Customizing the Visual Studio 2010 SharePoint Deployment Process Introduction to SharePoint Development SharePoint 2010 Unit and Integration Testing with Eric Shupps Building Enterprise Records Management Solutions for SharePoint 2010 Taming Information Chaos in SharePoint 2010 SharePoint 2010 Performance and Capacity Planning Best Practices Building Dynamic Applications with the SharePoint Client Object Model Articles by Eric Shupps eshupps The SharePoint Cowboy Eric Shupps' Ten Steps to Optimize SharePoint Performance Webcasts by Eric Shupps eshupps The SharePoint Cowboy Secrets of SharePoint Part 5: Configuring Microsoft Office SharePoint Server 2007 for Optimal Performance Creating End User SharePoint Solutions for Performance and Scalability SharePoint 2010 Performance Enhancements for Administrators by Eric Shupps Microsoft SharePoint Server 2010 for the ASP.NET Developer Eric Shupps on Following Best Practices and Avoiding Common Errors with Microsoft Office SharePoint Server 2007 Development Eric Shupps - SharePoint Performance and Capacity Planning Essentials Troubleshooting Common Performance Problems in SharePoint 2010 Videos by Eric Shupps eshupps The SharePoint Cowboy Channel 9 Interview with Eric Shupps SharePoint TechTalk with Eric Shupps - Different Views on Social Computing SharePoint Post-Deployment Planning and Management with Eric Shupps SmartTrack for SharePoint Feature Overview SmartTrack for SharePoint Podcasts by Eric Shupps eshupps The SharePoint Cowboy SharePoint Pod Show - Design for Performance (Eric Shupps) SharePoint Pod Show - Test Driven Development with Andrew Woodward and Eric Shupps eshupps The SharePoint Cowboy Run As Radio - Eric Shupps Improves SharePoint Performance
SmartTrack for SharePoint Eric Shupps Eric Alan Shupps eshupps @eshupps SharePoint Cowboy BinaryWave

 
​The SharePoint Cowboy


photo of  Eric Shupps
BinaryWave
611 S. Main St., Suite 400
Grapevine , TX , 76051 USA
Eric Shupps and Eric Alan Shupps with BinaryWave the BinaryWave Inc in BinaryWave Incorporated around SmartTrack beside SharePoint Monitoring through SharePoint alongside SharePoint Monitoring visiting @eshupps via eshupps near SharePoint performance and SharePoint management. The SharePoint cowboy eshupps BinaryWave and more on Operational Intelligence via Eric Alan Shupps SharePoint blog. SharePoint monitoring is a hot topic along with SharePoint Performance Measurement and SharePoint tips and tricks from Eric Shupps for SmartTrack. Another Eric Shupps on Technology and Eric Shupps on SharePoint with a new SharePoint Post from Eric Shupps. New BinaryWave post through BinaryWave Inc. and with another SharePoint blog we get to Eric Alan Shupps Blog about SharePoint development. That's Eric Shupps - BinaryWave or Eric Alan Shupps Fort Worth Grapevine Texas Dallas of BinaryWave talking about BinaryWave Operational Intelligence at the SharePoint Cowboy blog and on twitter as @eshupps. Of course SharePoint Administration is on topic for eshupps and another great post from Eric Shupps regarding BinaryWave SharePoint and SharePoint Maintenance.
September 14
Creating Permalinks for SharePoint Blog Post Items

Most commercial blogging platforms use a fixed URL structure, known as a "permalink", to identify posts – something like "http://www.myblog.com/2012/09/13/This-Is-My-Post.html". This structure makes it easy to reference a particular post, supports trackbacks/pingbacks, and makes it simple for search crawlers to locate content. Unfortunately, the SharePoint 2010 Blog template has no concept of how an actual blog platform should work – permalinks are an entirely foreign concept. Because SharePoint stores blog posts as individual list items, the URL structure is comprised of a fixed root path with a query string parameter for the item ID, such as "http://www.binarywave.com/blogs/eshupps/Lists/Posts/Post.aspx?ID=270". Awful stuff.

Short of writing an HTTP Handler to construct friendly URL's, SharePointers are stuck with this less-than-optimal format. That being said, it would be helpful if the various views for the Posts list in a blog actually used this link structure to refer to each item but, alas, they don't; instead, they use and even worse path identifier that references an application page in the _layouts directory with parameters for the list and item ID (i.e. "http://www.myblog.com/_layouts/listform.aspx?PageType=4&ListId={89CBE813-99F7-4257-A23A-5FEFC377336B}&ID=269"). This is the equivalent of not only forgetting to put bullets in your gun but leaving the gun behind at the saloon on your way to the OK Corral – in other words, it makes an already bad situation even worse.

This makes summary listings of blog entries, such as the Archives view or Categories, next to impossible for search engines to follow and other bloggers to reference. If your blog happens to be a subsite under a publishing web it's very likely that the Lockdown feature has been enabled which prevents readers from even accessing content in the _layouts directory. And if you are doing any type of SEO on your site at all then you likely have a robots.txt file with DISALLOW entries for system directories like _layouts, _vti_bin, _catalogs, etc. It's enough to make you want to pull your hair out (if you have any left at this point).

Strangely enough, if you examine the views on the Posts list you'll see a field entitled "Permalink". Now that sounds like a good solution to this problem, doesn't it? If only it were so. The permalink field is a computed column that renders an icon with the proper link to the post (as proper as it gets, anyway – it's still referencing '/Lists/Posts/Post.aspx?ID=[ItemID]') instead of a hyperlink wrapped around the Title text. You'll see this at the bottom of each post next to the email link and number of comments. That's just throwing salt in the wound – first, take away real permalink functionality, then give us a field that almost-but-not-quite renders a semi-permalink. Oh, happy day.

So what can we do to fix this problem? Well, to begin with, we can add a column for the permalink value we want to create, the value of which should look something like "< a href='http://www.myblog.com/Lists/Posts/Post.aspx?ID=1' >My Post Title< /a >" (spaces added to fool the rich text editor); however, if we just create a computed column (which would be the simplest solution) then SharePoint will spit out the text of our markup and not an actual hyperlink (so much for simple solutions). So we need to use a Hyperlink column, which requires the format "Link, Text", meaning our input should look like "http://www.myblog.com/Lists/Posts/Post.aspx?ID=1, My Post Title". Ok, great, but how do we get that into the new column without manually having to input it each time we create a new post? And, even more challenging, how do we go back and update all of our old posts to use the new value?

There are a couple of ways to approach the first part of the problem, one with code and one without. Using code, we can write an event receiver to fire on ItemUpdated, parse out the ID and Title, then set the link column value and update the list item. Using a no code approach, we can use a workflow to do essentially the same thing – run on created or updated, set the link field value to a dynamic string formatted as "Link, Title", and use lookups to get the ID and Title values. Simple enough and should work just fine on new items. But what about fixing up the links on all of the existing items?

This can be done either with code (probably a simple console app) or Powershell. As writing an executable is probably overkill for this particular situation, Powershell would be a quicker way to get the desired result. Either way, the process is identical – get the list, loop through the list item collection, extract the Title and ID values from each list item, construct a string and store it in the link field. Here's a script to do just that:

$site = new-object Microsoft.SharePoint.SPSite("http://www.myblog.com")
$web = $site.openweb()
$list = $web.lists["Posts"]
$items = $list.getItems()
foreach ($i in $items) {$i["PostLink"] = "http://www.binarywave.com/blogs/eshupps/Lists/Posts/Post.aspx?ID=" + $i.ID + ", " + $i.Title;$i["_ModerationStatus"] = 0;$i.update();}

There are a couple of things to note about this script. First, "PostLink" is the field that holds the link value (the name is arbitrary). It is an out-of-the-box Hyperlink field added to the Posts list. Second, don't forget to call Update() on each item or the changes won't persist to the database. Finally, and this one will give you heart palpitations if you forget to include it, be sure to Approve each list item by setting the _ModerationStatus field to zero (unless you've turned off approvals for the Posts list – it's enabled by default); otherwise, when you go back to your site to view the wonderful results of your handiwork you'll be presented with a blank web part on the default page of your blog. Manually approving hundreds of list items is nobody's idea of a good time.

The last step is simply to alter the various views of the Posts list (such as "Archive") to use the new link value field instead of the "Title [Linked to Item with Edit Menu]" field. Now you've got all the bases covered – the workflow will handle creation of the permalink when new posts are created, the Powershell script fixed up all the existing items, and the views contain the proper links. Job done.

Now, if we could only get a REAL permalink field in the SharePoint blog template the world would be a much happier place – birds would sing, the sun would shine, money would grow on trees, Dr. Pepper would flow in streams, beer would be free…yeah, whatever. Don't hold your breath.

Comments

What about CKS:EBE?

Hey Erik, cool script.

Have you checked out the Community Kit for SharePoint - Enhanced Blog Edition on Codeplex? One of their features is "SEO Friendly URL's - blog post URL's that look like /archive/2007/08/25/sharepoint-chart-tool.aspx instead of /Lists/Posts/ViewPost.aspx?ID=37"

We use the tool for the Black Blade blog. Once we extended our main master page to the blog section, it's been working very well.

-Eugene Rosenfeld
 on 9/14/2012 11:26 AM

RE: CKS:EBE

Eugene,

Good to hear from ya, bud!  No, I've not tried to use CKS:EBE on this site as it's too heavily customized and I just don't have time to go through the pain of converting everything over.  Moving it from 2007 caused a ton of problems so I'm trying to tweak it at this stage and not make any major changes.  When we move the site to 2013 I'll take on the task of fixing it properly.

Thanks for the input. 

FYI, if anyone wants it (and it's a great tool), the link is http://cksebe.codeplex.com/ 
Eric Shupps on 9/15/2012 10:20 AM

Re: Creating Permalinks for SharePoint Blog Post Items

We use the tool for the Black Blade blog. Once we extended our main master page to the blog section, it's been working very well.
 on 11/24/2015 4:23 AM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Comment Date *

Select a date from the calendar.
Enter the current date to prevent automated spambot comments.

Spam Prevention *


How many letters, not including spaces, does it take to spell "SharePoint Cowboy"?

Attachments

 
photo of Eric Shupps Eric Alan Shupps eshupps @eshupps SharePoint Cowboy BinaryWave Eric Shupps
BinaryWave
611 S. Main St., Suite 400
Grapevine , TX , 76051 USA

 
 
 
Eric Shupps Eric Alan Shupps eshupps @eshupps SharePoint Cowboy BinaryWave 

Eric Shupps LinkedIn Eric Shupps Twitter Eric Shupps Facebook Eric Shupps Google+
 
 

 


 


BinaryWave Eric Shupps eshupps The SharePoint Cowboy SharePoint monitoring SharePoint monitoring tool SharePoint metrics SharePoint administratrion SharePoint monitoring best practices SharePoint management SharePoint management tool SharePoint operations SharePoint operationsmanagement SharePoint administration SharePoint administration tool SharePoint SLA SharePoint service level agreement SharePoint operational intelligence SharePoint performance SharePoint performance monitoring SharePoint analytics SharePoint real-time SharePoint intelligence SharePoint ITIL SharePoint service operations SharePoint uptime SharePoint alerts SharePoint health SharePoint tools SharePoint metrics SharePoint diagnostics SharePoint SmartTrack SmartTrack Operational Intelligence


Copyright © 2013 BinaryWave, Inc. All rights reserved.
This site is brought to you by BinaryWave in cooperation with Eric Shupps Eric Alan Shupps eshupps @eshupps The SharePoint Cowboy. We hope you enjoy the SharePoint-related content on topics such as performance, monitoring, administration, operations, support, business intelligence and more for SharePoint 2010, SharePoint 2013 and Office 365 created by Eric Shupps The SharePoint Cowboy. We also hope you will visit our product pages to learn more about SmartTrack, Operational Analytics for SharePoint, SharePoint monitoring, and SharePoint administration, while also discovering great offers from our partners. Please visit the blog of Eric Alan Shupps, Twitter handle @eshupps, for more information on application development, the SharePoint community, SharePoint performance, and general technology topics. Eric Shupps Eric Alan Shupps eshupps @eshupps The SharePoint Cowboy is the founder and President of BinaryWave, a leading provider of operational support solutions for SharePoint. Eric Shupps Eric Alan Shupps eshupps @eshupps The SharePoint Cowboy has worked with SharePoint Products and Technologies since 2001 as a consultant, administrator, architect, developer and trainer. He is an advisory committee member of the Dallas/Ft. Worth SharePoint Community group and participating member of user groups throughout the United Kingdom. Eric Shupps Eric Alan Shupps eshupps @eshupps The SharePoint Cowboy has authored numerous articles on SharePoint, speaks at user group meetings and conferences around the world, and publishes a popular SharePoint blog at http://www.binarywave.com/blogs/eshupps.