C# 生成sitemap.txt文件

 百度需要提交xml和txt格式的

xml格式我在之前的文章写过,txt格式如图:

​编辑

它的格式就是单行一个网站不能有别的。每个Sitemap.txt文件可以添加的最多网址数目是50000个,如果多于这个数目的,可以再新开一个文件

核心 代码:

  //TXT
                string sitemaptxtname = "sitemap.txt";
                string sitemapTxTFileFullNamePath = string.Format(sitemapPath + "/{0}", sitemaptxtname);
                FileStream fs = new FileStream(sitemapTxTFileFullNamePath, FileMode.Create, FileAccess.Write);
                StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8);
                sw.BaseStream.Seek(0, SeekOrigin.End);
                sw.WriteLine("https://www.yadinghao.com");
                sw.Flush();
                sw.Close();

​编辑

按照你自己的 业务写就可以了

 百度需要提交xml和txt格式的

xml格式我在之前的文章写过,txt格式如图:

​编辑

它的格式就是单行一个网站不能有别的。每个Sitemap.txt文件可以添加的最多网址数目是50000个,如果多于这个数目的,可以再新开一个文件

核心 代码:

  //TXT
                string sitemaptxtname = "sitemap.txt";
                string sitemapTxTFileFullNamePath = string.Format(sitemapPath + "/{0}", sitemaptxtname);
                FileStream fs = new FileStream(sitemapTxTFileFullNamePath, FileMode.Create, FileAccess.Write);
                StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8);
                sw.BaseStream.Seek(0, SeekOrigin.End);
                sw.WriteLine("https://www.yadinghao.com");
                sw.Flush();
                sw.Close();

​编辑

按照你自己的 业务写就可以了

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在