Author: Manoj

Retrieve SharePoint Wiki HTML

image Recently, I had to retrieve the HTML of SharePoint Wiki pages. The only example I could find   was Arpan shah’s blog post about Grabbing Wiki content.

Turns out that it is not difficult as I thought and Wiki is just a List in SharePoint and you can retrieve the HTML content using the following code:

 

 

//ListId : List ID of Wiki List

//SiteUrl: Current Site URL

//ItemId: Item ID of wiki page

public string GetWikiHTML(string ListId, string ItemId, string SiteUrl)

{    

    //Get Site, Web, List and Retrieve ListItem

    using (SPSite Site = new SPSite(SiteUrl))

    {

        using (SPWeb Web = Site.OpenWeb())

        {

            SPList List = Web.Lists[new Guid(ListId)];

            SPListItem ListItem = List.GetItemById((Int32.Parse(ItemId)));

            string wikiHTML = String.Format("<html><body>{0}</body></html>", 

            ListItem[ListItem.Fields.GetFieldByInternalName("ows_WikiField").Id].ToString());

        }

     }

}

 

If you have read my previous post you will notice that is it very easy to retrieve ListID, ItemID and SiteURL using SharePoint Custom Actions (List of URL Tokens for Custom Action) or for the toolbar – on the page retrieval you can use following piece of code:

SPContext SiteContext = null;

String ListId, ItemId, SiteUrl;

 

// Get current context

SiteContext = SPContext.GetContext(HttpContext.Current);

if (SiteContext != null)

{

    ListId = SiteContext.List.ID.ToString(); // Get Current Wiki List ID

        ItemId = SiteContext.ListItem.ID.ToString(); // Get current Wiki page Id

        SiteUrl = SiteContext.Web.Url.ToString(); // Get SiteUrl of Wiki Page

}

 

Hope this helps. If there is a better way of doing this – please leave me a comment.

EditControlBlock (ECB) menu item in SharePoint Wiki and Blogs

In a recent project, I had to add an ECB item (shortcut menu, context menu) for wiki pages and blog posts in Microsoft Office SharePoint Server 2007. It was a quest to find the right ContentType.

Sharepoint ECB

To add a menu item for Wiki, you can create a Custom Action in the Feature.XML of your SharePoint feature. Here is how you define the custom action:

<CustomAction

Id="MyCustomID"

RegistrationType="ContentType"

RegistrationId="0x010108"

Location="EditControlBlock"

Sequence="500"

ImageUrl="/_layouts/images/icdocx.gif"

Title="$Resources:ResourceFileName,contextMenuText;">

<UrlAction Url="/_layouts/Processor.aspx?ListId={ListId}" />

</CustomAction>

 

 

For blog posts in SharePoint, you will have to create the following Custom Action:

<CustomAction

Id="MyCustomID"

RegistrationType="ContentType"

RegistrationId="0x0110"

Location="EditControlBlock"

Sequence="467"

ImageUrl="/_layouts/images/icdocx.gif"

Title="$Resources:ResourceFileName,contextMenuText;">

<UrlAction Url="/_layouts/Processor.aspx?ListId={ListId}" />

</CustomAction>

Note that the scope of the Feature should be Site Collection as Blogs are separate sites in SharePoint.

You can extend almost every type of menu by creating a custom action for it. In SharePoint all you need is the following three links to implement a Custom Action:

  1. Add Action to Sharepoint User interface
  2. Determinte ContentTypes, Locations and Groups
  3. Confirm in Base Content Type Hierarchy

Welcome to my Blog

I have finally decided to take a plunge in the world of blogging.  My Blog Statement?

Let’s see –

Purpose

This is my web blog. My perspective, my views, my rant. A lot of posts on this blog will relate to stuff in .NET development that you don’t encounter everyday. A reminder for us developers. Helping a developer one at a time.

About

I work in the development space of Microsoft. I have passion for technology and believe that we should outsource a lot of stuff we do to computers. I will create / update an About Me page in coming days.

I encourage you to share your comments and thoughts.

Let’s Begin …

About Me

Manoj Nagpal Hi, my name is Manoj Nagpal. I am a software developer. I live in Melbourne with my wife and a lot of Samsung Panels (connected to processors of course!).
My introduction to computers started with an Intel 80286 PC running MS DOS 3.3, the first day I turned on a computer – I had no clue about the OS or the commands. I was overwhelmed when I discovered that pressing “DEL” key displays a screen full of words (BIOS of course). This was the first thing I “found” on the computer.

Since then I thrive on “finding things”. In late 90’s I continued on to programming with COBOL, C++, Visual C++ (Win 32 programming with MCF) and Java. After completing my Masters in Information Technology at RMIT University, I now comfortably develop software in VB.NET and C#.

Technology I use

Computers and everything that comes with it has been a ver integral part of my life.
I spend much of my free time keeping up with the latest technology trends and devices (to an extent my budget permits me!) More on that later …