Bookmark Control (BE)

A simple Blog Engine control for Social Bookmarks.
It's not written as a extension since there are no events available for the post footer and I didn't want this portion to be part of each post content.

Bookmark Admin Panel

This is how the end result looks like

Add the following code to PostView.ascx found inside your theme folder

<script runat="server" language="c#">

    private string RenderBookmarks()
        string fileName = Context.Server.MapPath(BlogSettings.Instance.StorageLocation) + "bookmarks.xml";
        if (File.Exists(fileName))
            XmlDocument doc = new XmlDocument();

            System.IO.StringWriter sw = new System.IO.StringWriter();
            foreach (XmlNode node in doc.SelectNodes("bookmarks/bookmark"))
                HtmlAnchor hyperlnk = new HtmlAnchor();
                hyperlnk.Attributes.Add("rel", "nofollow");
                hyperlnk.Target = "_blank";
                hyperlnk.Name = node.Attributes["Name"].Value;

                string fullURL = node.Attributes["Url"].Value;
                fullURL = fullURL.Replace("[URL]", Post.AbsoluteLink.ToString());
                fullURL = fullURL.Replace("[TITLE]", Post.Title); 
                hyperlnk.HRef = fullURL;

                hyperlnk.InnerHtml = "<img src='" + Utils.RelativeWebRoot + "pics/socialicons/" + 
                                                    node.Attributes["ImageName"].Value + "' border='0'/>";
                hyperlnk.RenderControl(new HtmlTextWriter(sw));
            Post p = new Post();
            p = (Post)ViewState["Post"];

            return sw.ToString();

            return "Error in RenderBookmarks - bookmarks.xml not found";

HTML fragment to show the bookmarks in the footer (PostView.ascx)

<div class="bookmarks"> Share this post by <a rel="nofollow" href="mailto:?subject=<%=Post.Title %>&amp;
body=Thought you might like this: <%=Post.AbsoluteLink.ToString() %>"> <asp:Image ID="Image2" runat="Server" ImageUrl="~/pics/mail.gif" AlternateText="Share by email" /></a>
or online bookmarks <% =RenderBookmarks()%> /div>

Copy "bookmarks.xml" to "App_Data" folder.

Copy "bookmarks.aspx" & "bookmarks.cs" into "admin\Pages" folder

Copy all social icon images to "pics\socialicons"

Download the code and images here (381.92 kb)


Sukesh Sukesh Ashok Kumar
Works @ Microsoft

Chat with me!
who's online


All opinions posted here are those of the author and are in no way intended to represent the opinions of his employer. All posts are provided "AS IS" with no warranties, and confers no rights. © Copyright 2010

Recent Comments

Comment RSS

Sign in