Read website configuration documents

Source: Internet
Author: User

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

}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.