Home Sign In

Steven Van de Craen's Blog

Bloggings about SharePoint, .NET and more.

RSS Feed
  • Contact Me

Archives

  • July 2007 (19)
  • August 2007 (6)
  • September 2007 (3)
  • November 2007 (12)
  • October 2007 (4)
  • December 2007 (8)
  • January 2008 (6)
  • February 2008 (3)
  • March 2008 (2)

Categories

  • SharePoint 2003
  • SharePoint 2007
  • General
  • Office 2003
  • Office 2007
  • Excel Services
  • Dynamics NAV
  • SOAP
  • Search
  • Search Server 2008
  • .NET
  • CKS
  • IIS

Recent Posts

  • CKS:EBE 2.0 Final Release
  • TechDays 2008 wrap up
  • SharePoint Errors: 6482, 7888, 6398 and 7076
  • Feature Activation Dependency + Hidden = Automagic
  • FieldRefs node in new Content Type XML

Other Blogs

  • //BLOG: naked programmer
  • JOPX
  • Jan Tielens' Bloggings [MVP]
  • Serge van den Oever [Macaw]
  • Carlos Segura Sanz
  • -->Patrick Tisseghem's Blog [MVP SharePoint] -->
  • Remco Ploeg's Blog
  • SharePoint Blogs
  • Romeo Pruno
  • [email protected]
  • Andrew Connell [MVP MOSS]
  • Mark Harrison
  • Pedro Serrano
  • Clemens Vasters and the Indigettes
  • Kevin Boske
  • SharePoint Team Blog
  • Brian Jones: Office XML Formats
  • Mart Muller's Sharepoint Weblog
  • Joel Oleson's SharePoint Land
  • Kris' blog
  • STSADM Custom Extensions
  • Microsoft Enterprise Search Blog
  • Michaël's coding thoughts
  • Chris O'Brien's blog
  • John Holliday's SharePoint Reflections

SPListItem.ReplaceLink Method

A post about the ReplaceLink method of a Microsoft.SharePoint.SPListItem object.

This method replaces all instances of a given absolute URL with a new absolute URL inside a SharePoint List Item.

Remarks

  • Only applies to URLs formatted as hyperlink (Rich Text Field) or inside Hyperlink Fields (so this doesn't work for a plain text URL)
  • Only the hyperlink URL part is replaced (even if the hyperlink text matches the URL it doesn't get replaced)
  • Only works when 'Require documents to be checked out before they can be edited?' is false
  • Item version, approval status and modified date remain unchanged
  • Does not require item.Update(); the modification is instant and permanent

Now the biggest surprise to me was that this method also replaces URLs inside Microsoft Office Documents. The same rules (as described above) apply to documents.

Example

using (SPSite site = new SPSite("http://localhost"))
{
  using (SPWeb web = site.OpenWeb())
  {
    SPList list = web.GetList("/Documents");
   
SPListItem item = list.Items[0];
    item.ReplaceLink(
"http://www.sharepointblogs.com/vandest", "https://moss2007.be/blogs/vandest");
  }
}

References

http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.replacelink.aspx

Applies To

Windows SharePoint Services 3.0, Microsoft Office SharePoint Server 2007

 
Categories: SharePoint 2007

Trackback Url

 

Comments

Thursday, 27 Dec 2007 07:53 by Peter {faa780ce-0f0a-4c28-81d2-3667b71287fd}
I bet this is the same function used during SharePoint migrations. If it is, I'm betting that it has the same bug: URL-encoded URLs in the querystring are not changed. This comes into play when you have a link to create a new document. The URL generally looks like: http://moss.example.com/site/Tasks/NewForm.aspx?Source=[some very ugly URL-encoded URL!] Anyway, what I'm getting at is I encountered this specific bug; just throwing that out there.

Thursday, 27 Dec 2007 07:53 by Steven Van de Craen
Thanks for the heads up Peter. If I ever use this method I will be sure to test for this behaviour in advance !

Tuesday, 12 Feb 2008 02:46 by mInNaL
Hi there. When a customer make a "Custom List", I programmatically create a "Document Library" based on the "Custom List's" Title tag. Is it possible to make, so when the user click on the Custom List, then it should automatically redirect to the "Document Library". Can I use this "Item.ReplaceLink" for a Custom List property? Or is there any other way to fix this?

Wednesday, 13 Feb 2008 11:14 by Steven Van de Craen
Hi mInNaL, you seem to be talking about redirecting the link to a Custom List (not a single item) to a Document Library. This doesn't have anything to do with SPListItem. You could add a (hidden) Web Part on the CustomList Views to redirect to the Library ? Or you could modify the Title URL of a ListViewWebPart so that it redirects to a custom URL.

Leave a comment

Name

Url

Email

Comments

CAPTCHA Image Validation

© 2007 Steven Van de Craen — Powered by Community Kit for SharePoint: Enhanced Blog Edition.