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
}
}