读取网站配置文档

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;
using System.Net;
using System.Web;
using InsApp.word;

namespace InsApp.WebSearch
{

    public class ReadWebSiteXml
    {
        ///读取网站配置文档

        InsApp.word.FileClass CheckNullstr = new FileClass();
        string FilePath;

        public ReadWebSiteXml()
        {
            FilePath = System.Configuration.ConfigurationManager.AppSettings["Web_Info"];
            FilePath = System.Web.HttpContext.Current.Server.MapPath(FilePath);
        }

    #region  string[] ReadWebSiteTitle()读取xml文档
        /// <summary>
        /// 读取网站配置文件,得到相关内容
        /// </summary>
        /// <param name="FilePath"></param>
        public string[] ReadWebSiteTitle()
        {
            //Webname=title,WebMeta=webcontent,WebCopyright=Copyright
            //WebKey    关键字共有4个
            string[] WebSystem=new string[4];

            try
            {
                if (!File.Exists(FilePath))
                {
                    throw new Exception("文件不存在");
                }
                else
                {
                    ///读取配置文件 WebInfo/Info/Webname
                    using (XmlReader reader = XmlReader.Create(FilePath))
                    {
                        reader.Read();
                        reader.ReadStartElement("WebInfo");
                        reader.ReadStartElement("Info");
                        reader.ReadStartElement("Webname");
                        WebSystem[0] = reader.ReadString();
                        reader.ReadEndElement();
                        reader.ReadStartElement("WebMeta");         //网站meta
                        WebSystem[1] = reader.ReadString();
                        reader.ReadEndElement();
                        reader.ReadStartElement("WebCopyRight");
                        WebSystem[2] = reader.ReadString();         //WebCopyRight  页面底部文件
                        reader.ReadEndElement();
                        reader.ReadStartElement("WebKey");
                        WebSystem[3] = reader.ReadString();         //WebKey  meat关键字
                        reader.ReadEndElement();
                        reader.Close();
                        return WebSystem;
                    }
                }
            }
            catch(Exception ex)
            {

                throw new Exception(ex.Message.ToString());
            }

        }
        #endregion

    #region  string[] ReadWebSiteTitle(string FilePath,int ArrayLength)读取xml文档
/// <summary>
/// 读取网站配置文件,得到相关内容
/// </summary>
/// <param name="FilePath">网站配置文件</param>
/// <param name="ArrayLength">数组长度</param>
/// <param name="Obj_Source">对象长度</param>
/// <returns></returns>
        public string ReadWebSiteTitle(string FilePath)
        {
            string WebSystem = string.Empty;
            try
            {
                if (!File.Exists(FilePath))
                {
                    throw new Exception("文件不存在");
                }
                else
                {
                    XmlTextReader Reader = new XmlTextReader(FilePath);
                    Reader.WhitespaceHandling = WhitespaceHandling.None;

                    while (Reader.Read())
                    {
                        switch (Reader.NodeType)
                        {
                            case XmlNodeType.Text:
                                if (CheckNullstr.CheckNullstr(Reader.Value) == true)
                                {
                                    WebSystem+= "<option>"+Reader.Value.Trim()+"</option>";
                                }
                            break;
                        }
                    }
                    return WebSystem;
                }
            }
            catch(Exception ex)
            {

                throw new Exception(ex.Message.ToString());
            }

        }
        #endregion

    #region  读取压制视频的程序路径
        /// <summary>
        /// 读取网站配置文件,得到相关内容
        /// </summary>
        /// <param name="FilePath"></param>
        public string[] Read_Applcation_Path()
        {
            //WebKey    关键字共有4个
            string[] WebSystem = new string[2];
            string FilePath1=System.Web.HttpContext.Current.Server.MapPath("~//App_Config//Application.xml");
            try
            {
            if (CheckNullstr.Check_File(FilePath1, "file", false) == false)
            {
                throw new Exception("配置文件不存在,请重新配置站点。");
            }
            else
            {
                ///读取配置文件 App_Path/Application/ffmpeg    mencoder
                using (XmlReader reader = XmlReader.Create(FilePath1))
                {
                    reader.Read();
                    reader.ReadStartElement("App_Path");
                    reader.ReadStartElement("Application");
                    reader.ReadStartElement("ffmpeg");              //外部程序路径1
                    WebSystem[0] = reader.ReadString();
                    reader.ReadEndElement();
                    reader.ReadStartElement("mencoder");            //外部程序路径2
                    WebSystem[1] = reader.ReadString();
                    reader.ReadEndElement();
                    reader.Close();
                    return WebSystem;
                }
            }
            }
            catch (Exception ex)
            {

                throw new Exception(ex.Message.ToString());
            }

        }
        #endregion

    }
}

posted @ 2007-05-28 15:27  世之云枭  阅读(178)  评论(0编辑  收藏  举报