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
{
/// Read the website configuration document
Insapp. Word. fileclass checknullstr = new fileclass ();
String filepath;
Public readwebsitexml ()
{< br> filepath = system. configuration. configurationmanager. appsettings ["web_info"];
filepath = system. web. httpcontext. current. server. mappath (filepath);
}
# Region string [] readwebsitetitle () read XML documents
/// <Summary>
/// Read the website configuration file to obtain relevant information
/// </Summary>
/// <Param name = "filepath"> </param>
Public String [] readwebsitetitle ()
{
// Webname = title, webmeta = webcontent, webcopyright = Copyright
// There are 4 webkey keywords
String [] websystem = new string [4];
Try
{
If (! File. exists (filepath ))
{
Throw new exception ("the file does not exist ");
}
Else
{
/// Read the configuration file 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"); // website Meta
Websystem [1] = reader. readstring ();
Reader. readendelement ();
Reader. readstartelement ("webcopyright ");
Websystem [2] = reader. readstring (); // file at the bottom of the webcopyright page
Reader. readendelement ();
Reader. readstartelement ("webkey ");
Websystem [3] = reader. readstring (); // webkey meat keyword
Reader. readendelement ();
Reader. Close ();
Return websystem;
}
}
}
Catch (exception ex)
{
Throw new exception (ex. Message. tostring ());
}
}
# Endregion
# Region string [] readwebsitetitle (string filepath, int arraylength) read XML documents
/// <Summary>
/// Read the website configuration file to obtain relevant information
/// </Summary>
/// <Param name = "filepath"> website configuration file </param>
/// <Param name = "arraylength"> array length </param>
/// <Param name = "obj_source"> Object length </param>
/// <Returns> </returns>
Public String readwebsitetitle (string filepath)
{
String websystem = string. empty;
Try
{
If (! File. exists (filepath ))
{
Throw new exception ("the file does not exist ");
}
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 Program Path
/// <Summary>
/// Read the website configuration file to obtain relevant information
/// </Summary>
/// <Param name = "filepath"> </param>
Public String [] read_applcation_path ()
{
// There are 4 webkey keywords
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 ("the configuration file does not exist. Please reconfigure the site. ");
}
Else
{
/// Read the configuration file app_path/application/FFMPEG mencoder
Using (xmlreader reader = xmlreader. Create (filepath1 ))
{
Reader. Read ();
Reader. readstartelement ("app_path ");
Reader. readstartelement ("application ");
Reader. readstartelement ("FFMPEG"); // external program Path 1
Websystem [0] = reader. readstring ();
Reader. readendelement ();
Reader. readstartelement ("mencoder"); // external program Path 2
Websystem [1] = reader. readstring ();
Reader. readendelement ();
Reader. Close ();
Return websystem;
}
}
}
Catch (exception ex)
{
Throw new exception (ex. Message. tostring ());
}
}
# Endregion
}
}