In SharePoint 2007 and 2010 we have the option to create wiki sites or wiki libraries. By formatting text in the article with brackets ([[…]]) the author has the option to define links within the article. By defining these links the corresponding article is not created. But the link is renderd with a dashed line.

If you need to find all articles in a wiki with such missing links, you can read the wiki content from an article and parse for a hyperlink tag with the class “ms-missinglink”. Here is some sample code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.Xml;

namespace TestWikiContent
{
    class Program
    {
        static void Main(string[] args)
        {
            string url = "http://server:6000";

            using (SPSite site = new SPSite(url))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["Wiki"];

                    foreach (SPListItem item in list.Items)
                    {
                        string value = item[item.Fields.GetFieldByInternalName("WikiField").Title] as string;

                        XmlDocument xmlDoc = new XmlDocument();
                        xmlDoc.LoadXml(value);

                        XmlNode root = xmlDoc.DocumentElement;

                        string xpath = "//a[@class='ms-missinglink']";

                        XmlNodeList missingLinks = root.SelectNodes(xpath);

                        foreach (XmlNode missingLink in missingLinks)
                        {
                            string href = missingLink.Attributes["href"].Value;
                            string text = missingLink.InnerText;

                            Console.WriteLine("Missing link: {0} ('{1}')", text, href);
                        }
                    }
                }
            }
        }
    }
}

For this sample we have a site at “http://server:6000” with a wiki library called “Wiki”. The content for each article could be found in the field “WikiField” (it’s the internal name of the field).

Enjoy!

Advertisements