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");

            }

        }

    }
  • 相关阅读:
    打包时,指定war包的名称
    java读取properties文件的配置信息
    java日期时间处理集合
    jpa使用原生SQL查询数据库like的用法
    讲讲升级macOS Big Sur后的感受
    eclipse failed to create jvm The JVM shared library "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/../lib/server/libjvm.dylib" does not contain the JNI_CreateJavaVM symbol.
    Xcode12 占用空间过大的解决方法及彻底删除Xcode
    Entry name 'classes.dex' collided
    multidex Unable to get provider com.vivo.upgrade.library.provider.FileProvider
    android保存完了,自动关闭软键盘
  • 原文地址:https://www.cnblogs.com/jackrebel/p/1286182.html
Copyright © 2011-2022 走看看