C# 生成sitemap.txt文件

 zhangy  2023-02-24 09:19:29  929  6  0

 百度需要提交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();

​编辑

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


作者禁止了评论
评论内容