Month: June 2008

Add domain user to local vista administrator group

Recently I had to re-format my work laptop and I decided to fix one of the most annoying thing that I dealt with everyday but I was too lazy to research.

My company has a group policy setup for UAC. We need to have it enabled at all times but the pain of entering the username (domainusername) and password every time I wanted to start visual studio or IIS console was very unproductive and tedious.

Turns out a simple command at CMD prompt can do the trick:

net localgroup Administrators /add domainusername

Behold – no more password – one click and we are elevated. Oh the joys of Windows Vista.

Update: This works for Windows 7 as well. – 8th June 2009

Retrieving SharePoint Blog Post HTML

image Following my series of retrieving HTML from SharePoint – I had to recently retrieve the HTML from the Blog post in SharePoint.

One again – it is pretty straight forward but as the Blogs are a different site compared to SharePoint MySite – you will need to develop a feature at a Site Collection level.

 

 

public bool Convert(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["Posts"];

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

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

                   ListItem["Body"].ToString());

        }

    }

}

The list you are retrieving data from here is “Posts”.

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.