Skip to content

Instantly share code, notes, and snippets.

@ernado-x
Last active November 3, 2021 11:05
Show Gist options
  • Save ernado-x/94e486ce4a6ddd6e8cd5e28d61f13d2a to your computer and use it in GitHub Desktop.
Save ernado-x/94e486ce4a6ddd6e8cd5e28d61f13d2a to your computer and use it in GitHub Desktop.
X.Web.Sitemap - simple example
class Program
{
static void Main(string[] args)
{
var sitemap = new Sitemap();
sitemap.Add(new Url
{
ChangeFrequency = ChangeFrequency.Daily,
Location = "http://www.example.com",
Priority = 0.5,
TimeStamp = DateTime.Now
});
sitemap.Add(CreateUrl("http://www.example.com/link1"));
sitemap.Add(CreateUrl("http://www.example.com/link2"));
sitemap.Add(CreateUrl("http://www.example.com/link3"));
sitemap.Add(CreateUrl("http://www.example.com/link4"));
sitemap.Add(CreateUrl("http://www.example.com/link5"));
//Save sitemap structure to file
sitemap.Save(@"d:\www\example.com\sitemap.xml");
//Split a large list into pieces and store in a directory
sitemap.SaveToDirectory(@"d:\www\example.com\sitemaps");
//Get xml-content of file
Console.Write(sitemap.ToXml());
Console.ReadKey();
}
private static Url CreateUrl(string url)
{
return new Url
{
ChangeFrequency = ChangeFrequency.Daily,
Location = url,
Priority = 0.5,
TimeStamp = DateTime.Now
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment