sparky74
asked on
c# help building a link string
Hi
I have made some changes in my blog and want to change the url link for the blog tags.
I almost got it, but cant get the last part
using the code below my tag outputs as
anchor text = Test
and url link = http://www.example.com/appliance/.aspx?brand=Test
The Category part shows
anchor text = Washing Machines
and url link = http://www.example.com/appliance/washing-machines.aspx
I am trying to get the Tag to be like this
anchor text = Test Washing Machines (so this will be the tag + the Category)
and then the url link to be
http://www.example.com/appliance/washing-machines.aspx?brand=test
so the category gets inserted into the url,, the spaces get replaced with - and its all lowercase
can anyone help me correct my code below please
I have made some changes in my blog and want to change the url link for the blog tags.
I almost got it, but cant get the last part
using the code below my tag outputs as
anchor text = Test
and url link = http://www.example.com/appliance/.aspx?brand=Test
The Category part shows
anchor text = Washing Machines
and url link = http://www.example.com/appliance/washing-machines.aspx
I am trying to get the Tag to be like this
anchor text = Test Washing Machines (so this will be the tag + the Category)
and then the url link to be
http://www.example.com/appliance/washing-machines.aspx?brand=test
so the category gets inserted into the url,, the spaces get replaced with - and its all lowercase
can anyone help me correct my code below please
/// Displays the Post's categories seperated by the specified string.
/// </summary>
protected virtual string CategoryLinks(string separator)
{
string[] keywords = new string[Post.Categories.Count];
string link = "<a href=\"{0}{1}.aspx\">{2}</a>";
string path = VirtualPathUtility.ToAbsolute("~/");
for (int i = 0; i < Post.Categories.Count; i++)
{
if (Category.Categories.Contains((Category)Post.Categories[i]))
{
string category = Category.GetCategory(Post.Categories[i].Id).Title;
keywords[i] = string.Format(CultureInfo.InvariantCulture, link, path, Utils.RemoveIllegalCharacters(category), category).ToLower();
}
}
return string.Join(separator, keywords);
}
/// <summary>
/// Displays the Post's tags seperated by the specified string.
/// </summary>
protected virtual string TagLinks(string separator)
{
if (Post.Tags.Count == 0)
return null;
string[] keywords = new string[Post.Categories.Count];
string[] tags = new string[Post.Categories.Count];
string link = "<a href=\"{0}{1}\">{2}</a>";
string path = Utils.RelativeWebRoot +".aspx?brand=";
for (int i = 0; i < Post.Categories.Count; i++)
{
if (Category.Categories.Contains((Category)Post.Categories[i]))
{
string category = Category.GetCategory(Post.Categories[i].Id).Title;
keywords[i] = string.Format(CultureInfo.InvariantCulture, link, path, Utils.RemoveIllegalCharacters(category), category).ToLower();
}
}
for (int i = 0; i < Post.Tags.Count; i++)
{
string tag = Post.Tags[i];
tags[i] = string.Format(CultureInfo.InvariantCulture, link, path, HttpUtility.UrlEncode(tag), HttpUtility.HtmlEncode(tag));
}
return string.Join(separator, tags);
}
ASKER
Hi
No i'm just trying to add the category value into the url
No i'm just trying to add the category value into the url
ASKER
my current link looks like
url link = http://www.example.com/appliance/.aspx?brand=Test
but I want to add the category value, for example Washing Machines
so my url link will look like this
url link = http://www.example.com/appliance/washing-machines.aspx?brand=Test
url link = http://www.example.com/appliance/.aspx?brand=Test
but I want to add the category value, for example Washing Machines
so my url link will look like this
url link = http://www.example.com/appliance/washing-machines.aspx?brand=Test
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This was just the help I needed. Thank you so much your code worked a treat!
http://msdn.microsoft.com/en-us/library/ms972974.aspx