We're migrating a site collection to a new farm (SP2010 to SP2010, same version). In the old farm, the site collection resided at the root of the web application (http://oldsitecollection/). As part of a new governance strategy, in the new farm it will be under a managed path (http://newfarm/sites/sitecollection).

Within the site collection is a blog site (./Blog). Within this blog, all the posts reference images using the absolute path "/Blog/Photos/imageexample.jpg". This absolute reference does not play nice in the new farm as instead of referencing "http://newfarm/sites/sitecollection/Blog/Photos/imageexample.jpg" it now references "http://newfarm/Blog/Photos/imageexample.jpg". The images do not appear as expected as the URL to their location is now incorrect.

Is there a way to update all the URL references at once? Maybe a tool or a bulk operation of some sort? We are currently considering either editing each post and image individually or writing a PowerShell/C# application to go through each item and update the URL.


Not 100% certain this will work, but in theory it's sound and it's the first thing I'd try in this instance

  1. Backup the site collection using powershell.
  2. Restore the site collection to the new location.
  3. Update the ServerRelativeUrl of the blog web.
  4. Ensure you call the .Update() method of the blog web object

Edit: if you're looking to change Urls with an post body try something like this in PowerShell

$oldImagePath = "/Blog/Images/"
$newImagePath = "/sites/Blog/Images/"
$web = Get-SPWeb $webUrl
$postList = $web.Lists["Posts"]
foreach ($post in $postList.Items)

    $postBody = $post["Body"]
    $postBody = $postBody.Replace($oldImagePath, $newImagePath)
    $post["Body"] = $postBody

Of course you'll need to fix up the list name and field name to match what they actually are but that should acheive the change you desire (or close enough that you can get there)

  • I checked the ServerRelativeURL property of both the restored site collection and the restored blog site and they are both expected for the new farm. When you edit the image location in an affected blog post it will automatically resolve correctly for the new farm too, so this makes sense that the ServerRelativeURL is correct. I think the issue is perhaps the the HTML within the post is static and doesn't update during the backup/restore.
    – shufler
    Nov 24 '11 at 21:19
  • To clarify, the blog site's ServerRelativeURL property is "/sites/sitecollection/blog" following the restore.
    – shufler
    Nov 24 '11 at 21:24
  • Ahhh yup, that would make sense. IIRC the blog posts are held in a list with a Rich Content field. I'd itterate through the list and do some string manipulation on the rich text field. I'll bang out something real quick here.
    – GavinB
    Nov 25 '11 at 2:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.