The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
<
asp:Repeater
ID
=
"BookmarksRepeater"
runat
=
"server"
>
<
ItemTemplate
>
<
asp:HyperLink
ID
=
"BookmarkLink"
runat
=
"server"
>
<
asp:Image
ID
=
"BookmarkImage"
runat
=
"server"
/>
</
asp:HyperLink
>
</
ItemTemplate
>
</
asp:Repeater
>
<
bookmarks
>
<
itemTemplate
>
<
bookmark
title
=
"Facebook"
name
=
"Facebook"
>
<
url
>
<![CDATA[http://www.facebook.com/sharer.php?u={0}&t={1}]]>
</
url
>
</
bookmark
>
<
bookmark
title
=
"Twitter"
name
=
"twitter"
>
<
url
>
<![CDATA[http://twitter.com/home?status=Read "{1}" from {0}]]>
</
url
>
</
bookmark
>
...
</
itemTemplate
>
<
extendedProperty
>
<
image
>
<
imageSize
>48</
imageSize
> <
imagePath
>
<![CDATA[~/CustomControls/ControlTemplates/BookMarkImages/{0}_{1}.png]]>
</
imagePath
>
</
image
>
</
extendedProperty
>
</
bookmarks
>
using
System;
using
System.ComponentModel;
using
System.Web;
using
System.Web.UI.WebControls;
using
System.Xml;
using
System.Xml.XPath;
using
Telerik.Cms;
using
Telerik.Cms.Web;
using
Telerik.Cms.Web.UI;
namespace
Sitefinity.Samples.WebControls
{
/// <summary>
/// Summary description for PageSocialBookmarks
/// </summary>
public
class
PageSocialBookmarks : SimpleControl
{
#region Fields
private
string
socialBookmarksPath =
"~/CustomControls/ControlTemplates/SocialBookMarks.xml"
;
private
string
layoutTemplatePath =
"~/CustomControls/ControlTemplates/SocialBookmarks.ascx"
;
private
string
bookmarkImagesPath;
private
string
bookmarkImagesSize;
private
string
pageTitle;
private
string
pagePath;
#endregion
#region Properties
[WebEditor(
"Telerik.FileManager.UrlWebEditor, Telerik.FileManager"
), Category(
"Appearance"
)]
public
override
string
LayoutTemplatePath
{
get
{
object
obj2 =
this
.ViewState[
"LayoutTemplatePath"
];
if
(obj2 !=
null
)
{
return
(
string
)obj2;
}
return
layoutTemplatePath;
}
set
{
this
.ViewState[
"LayoutTemplatePath"
] = value;
}
}
//set path to xml file containing social bookmarks
[WebEditor(
"Telerik.FileManager.UrlWebEditor, Telerik.FileManager"
), Category(
"Data"
)]
public
string
SocialBookmarksPath
{
get
{
object
obj2 =
this
.ViewState[
"SocialBookmarksPath"
];
if
(obj2 !=
null
)
{
return
(
string
)obj2;
}
return
socialBookmarksPath;
}
set
{
this
.ViewState[
"SocialBookmarksPath"
] = value;
}
}
#endregion
#region Methods
protected
override
void
CreateChildControls()
{
if
(Page ==
null
|| DesignMode)
{
Label noDesignModeLabel =
new
Label();
noDesignModeLabel.Text =
"The Social Bookmarks control cannot be rendered in Design Mode"
;
this
.Controls.Add(noDesignModeLabel);
}
else
{
ICmsPage cmsPage = ((CmsSiteMapNode)SiteMap.CurrentNode).GetCmsPage();
base
.CreateChildControls();
this
.pagePath = HttpContext.Current.Request.Url.ToString();
this
.pageTitle = cmsPage.Title;
GetBookmarkProperties();
XmlDataSource bookmarksDataSource =
new
XmlDataSource();
bookmarksDataSource.DataFile =
this
.socialBookmarksPath;
bookmarksDataSource.XPath =
"bookmarks/itemTemplate/bookmark"
;
bookmarksDataSource.ID =
"bookmarksDataSource"
;
this
.Container.Controls.Add(bookmarksDataSource);
BookmarksRepeater.DataSource = bookmarksDataSource;
BookmarksRepeater.ItemDataBound +=
new
RepeaterItemEventHandler(BookmarksRepeater_ItemDataBound);
BookmarksRepeater.DataBind();
}
}
//get settings for bookmarks image path and image size from xml
void
GetBookmarkProperties()
{
XmlReaderSettings settings =
new
XmlReaderSettings();
settings.IgnoreComments =
true
;
settings.IgnoreProcessingInstructions =
true
;
settings.IgnoreWhitespace =
true
;
XmlReader reader = XmlReader.Create((HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + ResolveUrl(
this
.socialBookmarksPath)), settings);
XmlDocument xmlDoc =
new
XmlDocument();
xmlDoc.Load(reader);
var imageSize = xmlDoc.GetElementsByTagName(
"imageSize"
);
var imagePath = xmlDoc.GetElementsByTagName(
"imagePath"
);
if
(imageSize.Count > 0)
{
this
.bookmarkImagesSize = imageSize[0].InnerText;
}
if
(imagePath.Count > 0)
{
this
.bookmarkImagesPath = imagePath[0].InnerText;
}
}
void
BookmarksRepeater_ItemDataBound(
object
sender, RepeaterItemEventArgs e)
{
if
(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
XPathNavigator navigator = ((IXPathNavigable)e.Item.DataItem).CreateNavigator();
XmlElement xmlElement = (XmlElement)navigator.UnderlyingObject;
HyperLink BookmarkLink = (HyperLink)e.Item.FindControl(
"BookmarkLink"
);
Image BookmarkImage = (Image)e.Item.FindControl(
"BookmarkImage"
);
BookmarkLink.NavigateUrl=
string
.Format(xmlElement.InnerText,
this
.pagePath,
this
.pageTitle);
BookmarkLink.ToolTip = xmlElement.GetAttribute(
"title"
);
BookmarkImage.ImageUrl =
string
.Format(
this
.bookmarkImagesPath, xmlElement.GetAttribute(
"name"
),
this
.bookmarkImagesSize);
}
}
//reference to the bookmarks repeater
[Browsable(
false
)]
public
Repeater BookmarksRepeater
{
get
{
return
base
.Container.GetControl<Repeater>(
"BookmarksRepeater"
,
false
, Telerik.Framework.Web.TraverseMethod.DepthFirst);
}
set
{
this
.BookmarksRepeater = value;
}
}
#endregion
}
}
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.