Here is a code snippet to sort Blogengine.net link list.
You want to modify the following C# file: BlogEngine\BlogEngine.NET\Custom\Widgets\LinkList\widget.ascx.cs
Listed below is the original code from the method: LoadWidget()
//-----------------
//Orginal code
//-----------------
foreach (XmlNode node in links)
{
var a = new HtmlAnchor();
if (node.Attributes != null)
{
if (node.Attributes["url"] != null)
{
a.HRef = node.Attributes["url"].InnerText;
}
if (node.Attributes["title"] != null)
{
a.InnerText = node.Attributes["title"].InnerText;
}
if (node.Attributes["newwindow"] != null &&
node.Attributes["newwindow"].InnerText.Equals("true", StringComparison.OrdinalIgnoreCase))
{
a.Target = "_blank";
}
}
var li = new HtmlGenericControl("li");
li.Controls.Add(a);
this.ulLinks.Controls.Add(li);
}
Replace the code above with the following:
The updated code starts at...
//--------------------------------------------------
//1. Put links in a table, the sort and process
//--------------------------------------------------
public override void LoadWidget()
{
var settings = this.GetSettings();
var doc = new XmlDocument();
if (settings["content"] != null)
{
doc.InnerXml = settings["content"];
}
var links = doc.SelectNodes("//link");
if (links == null)
{
return;
}
if (links.Count == 0)
{
this.ulLinks.Visible = false;
}
else
{
//--------------------------------------------------
//1. Put links in a table, the sort and process
//--------------------------------------------------
DataTable DtLinks = new System.Data.DataTable();
DtLinks.Columns.Add("URL", typeof(String));
DtLinks.Columns.Add("Title", typeof(String));
DtLinks.Columns.Add("Target", typeof(String));
//--------------------------------------------------
//2. Add to table
//--------------------------------------------------
DataRow dr = DtLinks.NewRow();
foreach (XmlNode node in links)
{
if (node.Attributes != null)
{
//Create Row and Default Values
dr = DtLinks.NewRow();
dr["URL"] = string.Empty;
dr["Title"] = string.Empty;
dr["Target"] = string.Empty;
if (node.Attributes["url"] != null)
{
dr["URL"] = node.Attributes["url"].InnerText.ToString();
}
if (node.Attributes["title"] != null)
{
dr["Title"] = node.Attributes["title"].InnerText.ToString();
}
if (node.Attributes["newwindow"] != null &&
node.Attributes["newwindow"].InnerText.Equals("true", StringComparison.OrdinalIgnoreCase))
{
dr["Target"] = "_blank";
}
DtLinks.Rows.Add(dr);
}
}
DtLinks.AcceptChanges();
//--------------------------------------------------
// 3. Loop through table and add to list item.
//--------------------------------------------------
DataView View = DtLinks.DefaultView;
View.Sort = "Title";
foreach (DataRowView row in View)
{
var a = new HtmlAnchor();
a.HRef = row["URL"].ToString();
a.InnerText = row["Title"].ToString();
if (row["Target"].ToString() != string.Empty) a.Target = row["Target"].ToString();
var li = new HtmlGenericControl("li");
li.Controls.Add(a);
this.ulLinks.Controls.Add(li);
}
}
}