zoukankan      html  css  js  c++  java
  • 控制台程序 自动生成Google sitemaps地图文件

    using System;

    using System.Collections.Generic;

    using System.Text;

    using System.Data;

    using System.Data.SqlClient;

    using System.Configuration;

    using System.Windows.Forms;

    using System.IO;



    namespace SiteMaps

    {

       
    class Program

        {

           
    static void Main(string[] args)

            {

    Console.WriteLine(
    "SQL语句");

               
    string sql = null;

                sql
    = Console.ReadLine();



               
    //Console.WriteLine("请输入文件名(路径)");

               
    //string file = null;

               
    //file = Console.ReadLine();

                string file = Application.StartupPath + "/" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xml";

                StreamWriter sw
    = new StreamWriter(file);

                sw.WriteLine(
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

                sw.WriteLine(
    "<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\">");

                sw.WriteLine(
    "<url>");

                sw.WriteLine(
    "<loc>{0}</loc>", ConfigurationManager.AppSettings["domain"]);

                sw.WriteLine(
    "<lastmod>{0}</lastmod>", DateTime.Now.ToString("yyyy-MM-dd"));

                sw.WriteLine(
    "<changefreq>daily</changefreq>");

                sw.WriteLine(
    "<priority>1.0</priority>");

                sw.WriteLine(
    "</url>");



                Console.WriteLine(
    "开始生成……");



               
    using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["db"].ConnectionString))

                {

                    SqlCommand cmd
    = new SqlCommand(sql, conn);

                    conn.Open();

                   
    using (SqlDataReader dr = cmd.ExecuteReader())

                    {

                       
    while (dr.Read())

                        {

                           
    string url = dr[0].ToString();

                            sw.WriteLine(
    "<url>");

                            sw.WriteLine(
    "<loc>{0}</loc>", url);

                            sw.WriteLine(
    "<lastmod>{0}</lastmod>", DateTime.Now.ToString("yyyy-MM-dd"));

                            sw.WriteLine(
    "<changefreq>daily</changefreq>");

                            sw.WriteLine(
    "</url>");

                            Console.WriteLine(url);

                        }

                        dr.Close();

                    }

                    conn.Close();

                }



                sw.WriteLine(
    "</urlset>");

                sw.Close();

                Console.WriteLine(
    "生成成功!\a");

            }

        }

    }
  • 相关阅读:
    c#-全局键盘钩子
    C#-自动获取IP
    C#-自动获取IP
    C#-获取CPUID
    C#-获取CPUID
    手动添加导入表修改EXE功能
    安装全局消息钩子实现dll窗体程序注入
    手动添加导入表修改EXE功能
    虚拟桌面模拟查找点击自绘控件
    虚拟桌面模拟查找点击自绘控件
  • 原文地址:https://www.cnblogs.com/jackrebel/p/1286182.html
Copyright © 2011-2022 走看看