Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Discussions > Google sitemaps (Archives - *read only*) > C# .net Code for a sitemap generation and it takes care of the date!
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alexandre (www.pointnetsolutions.co m)  
View profile  
(2 users)  More options Jun 5 2005, 1:17 pm
From: Alexandre (www.pointnetsolutions.com)
Date: Sun, 05 Jun 2005 10:17:03 -0700
Local: Sun, Jun 5 2005 1:17 pm
Subject: C# .net Code for a sitemap generation and it takes care of the date!
.net c# Code for generating a SiteMap

Enjoy

///Using

Page.Response.ContentType = "text/xml";

SiteMapFeedGenerator gen = new
SiteMapFeedGenerator(Page.Response.Output);

gen.WriteStartDocument();

//Add items to the list
gen.WriteItem("http://www.pointnetsolutions.com/default.aspx",DateTime.Now);

gen.WriteEndDocument();
gen.Close();

///Object

public class SiteMapFeedGenerator
        {
            XmlTextWriter writer;
            public SiteMapFeedGenerator( System.IO.Stream stream,
System.Text.Encoding encoding )
            {
                writer = new XmlTextWriter(stream, encoding);
                writer.Formatting = Formatting.Indented;
            }
            public SiteMapFeedGenerator( System.IO.TextWriter w )
            {
                writer = new XmlTextWriter(w);
                writer.Formatting = Formatting.Indented;
            }
            /// <summary>
            /// Writes the beginning of the SiteMap document
            /// </summary>
            public void WriteStartDocument()
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("urlset");

writer.WriteAttributeString("xmlns","http://www.google.com/schemas/sitemap/0.84");
            }
            /// <summary>
            /// Writes the end of the SiteMap document
            /// </summary>
            public void WriteEndDocument()
            {
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
            /// <summary>
            /// Closes this stream and the underlying stream
            /// </summary>
            public void Close()
            {
                writer.Flush();
                writer.Close();
            }

            public void WriteItem(string link, DateTime publishedDate)
            {
                writer.WriteStartElement("url");
                writer.WriteElementString("loc",link);

writer.WriteElementString("lastmod",formatDate(publishedDate));
                writer.WriteElementString("changefreq","always");
                writer.WriteElementString("priority","0.8");
                writer.WriteEndElement();
            }

            public string formatDate(DateTime d)
            {
                string date = "";
                date = d.Year+ "-";
                if(d.Month.ToString().Length == 1)
                {
                    date += "0"+d.Month +"-";
                }
                else
                {
                    date += d.Month +"-";
                }

                if(d.Day.ToString().Length == 1)
                {
                    date += "0"+d.Month;
                }
                else
                {
                    date += d.Day;
                }

                return date;
            }
        }


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
news@thozie.de  
View profile  
 More options Jun 5 2005, 1:35 pm
From: "[email address]"
Date: Sun, 05 Jun 2005 10:35:12 -0700
Local: Sun, Jun 5 2005 1:35 pm
Subject: Re: C# .net Code for a sitemap generation and it takes care of the date!
You could use DateTime d; d.ToString( "s" ); this would format the
DateTime correctly...

Thomas


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Waitman Gobble  
View profile  
 More options Jun 5 2005, 3:11 pm
From: Waitman Gobble
Date: Sun, 05 Jun 2005 19:11:41 -0000
Local: Sun, Jun 5 2005 3:11 pm
Subject: Re: C# .net Code for a sitemap generation and it takes care of the date!
Hi

 System.Text.Encoding encoding

You would have to make sure your system encoding defaults to utf-8 if i
am not mistaken. shouldn't this be specified (ie, override the default)
?

take care

Waitman


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexandre (www.pointnetsolutions.co m)  
View profile  
 More options Jun 5 2005, 9:04 pm
From: Alexandre (www.pointnetsolutions.com)
Date: Mon, 06 Jun 2005 01:04:33 -0000
Local: Sun, Jun 5 2005 9:04 pm
Subject: Re: C# .net Code for a sitemap generation and it takes care of the date!
so far this does the utf-8 encoding ...

as for the ToString("s") i did not know i will make the correction
thank you for the idea.


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
developerz  
View profile  
 More options Jun 5 2005, 11:31 pm
From: developerz
Date: Sun, 05 Jun 2005 20:31:24 -0700
Local: Sun, Jun 5 2005 11:31 pm
Subject: Re: C# .net Code for a sitemap generation and it takes care of the date!
I was getting an Invalid date errir from google when I just used the
ToString("s") .  I changed my date format to:
DateTime.Now.ToString("s") + "+00:00";   and google accepted my site
map.

d.


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexandre (www.pointnetsolutions.co m)  
View profile  
 More options Jun 5 2005, 11:36 pm
From: Alexandre (www.pointnetsolutions.com)
Date: Sun, 05 Jun 2005 20:36:10 -0700
Local: Sun, Jun 5 2005 11:36 pm
Subject: Re: C# .net Code for a sitemap generation and it takes care of the date!
I dont know how google  uses all this new information of how often they
will index pages,
but does the time of day really come into play??  i would really like
to know what makes this new algorythm tick to know how to adjust all
these sitemaps and sitemap indexs

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
softplus  
View profile  
 More options Jun 18 2005, 4:57 pm
From: softplus
Date: Sat, 18 Jun 2005 20:57:13 -0000
Local: Sat, Jun 18 2005 4:57 pm
Subject: Re: C# .net Code for a sitemap generation and it takes care of the date!
If you use >> DateTime.Now.ToString("s") + "+00:00" << then you should
make sure that your date/time is in UTC (i.e. zero UTC offset, as
specified). You can do this like this:

  TimeZone tz;
  tz = TimeZone.CurrentTimeZone;

and then ....  >> tz.ToUniversalTime(Now).ToString("s") + "+00:00" <<

(assuming that your server has the same timezone as your local system
does ;))

- John


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexandre (www.pointnetsolutions.co m)  
View profile  
 More options Jun 22 2005, 11:46 am
From: Alexandre (www.pointnetsolutions.com)
Date: Wed, 22 Jun 2005 08:46:15 -0700
Local: Wed, Jun 22 2005 11:46 am
Subject: Re: C# .net Code for a sitemap generation and it takes care of the date!
Hey John,

all this was changed in the current version im using in my app, i also
modified it to do the Index of sitemaps.

At the current moment i am working on making an Atom feed, and I have
recently finished a rss feed reader / indexer sends it to database.


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google