今天写了一个读取Xml数据库的实例,其中在web.config中配置了xml的绝对路径,我们要读取这些路径
<connectionStrings>
<add name="BOARDFILEPATH" connectionString="~/XmlDatabase/Board.xml"/>
<add name="TITLEFILEPATH" connectionString="~/XmlDatabase/Title.xml"/>
<add name="REPLYFILEPATH" connectionString="~/XmlDatabase/Reply.xml"/>
<add name="ATTACHMENTFILEPATH" connectionString="~/XmlDatabase/Attachment.xml"/>
<add name="MESSAGEFILEPATH" connectionString="~/XmlDatabase/Message.xml"/>
<add name="MESSAGESHIELDFILEPATH" connectionString="~/XmlDatabase/MessageShield.xml"/>
<add name="USERSTATFILEPATH" connectionString="~/XmlDatabase/UserStat.xml"/>
</connectionStrings>
这些路径都是在项目中的,所以我们读到它的绝对路径,需要用到server.MapPath,在这里,我们创建了一个用来封装这些路径的类
public class XmlBBS
{
public XmlBBS()
{
///
}
private static string boardFilePath;
public static string BoardFilePath
{
get { return boardFilePath; }
set { boardFilePath = value; }
}
private static string titleFilePath;
public static string TitleFilePath
{
get { return titleFilePath; }
set { titleFilePath = value; }
}
private static string replyFilePath;
public static string ReplyFilePath
{
get { return replyFilePath; }
set { replyFilePath = value; }
}
private static string attachmentFilePath;
public static string AttachmentFilePath
{
get { return attachmentFilePath; }
set { attachmentFilePath = value; }
}
private static string messageFilePath;
public static string MessageFilePath
{
get { return messageFilePath; }
set { messageFilePath = value; }
}
private static string messageShieldFilePath;
public static string MessageShieldFilePath
{
get { return messageShieldFilePath; }
set { messageShieldFilePath = value; }
}
private static string userStatFilePath;
public static string UserStatFilePath
{
get { return userStatFilePath; }
set { userStatFilePath = value; }
}
public static void SystemInit(HttpServerUtility server)
{
boardFilePath = server.MapPath(
ConfigurationManager.ConnectionStrings["BOARDFILEPATH"].ConnectionString
);
titleFilePath = server.MapPath(
ConfigurationManager.ConnectionStrings["TITLEFILEPATH"].ConnectionString
);
replyFilePath = server.MapPath(
ConfigurationManager.ConnectionStrings["REPLYFILEPATH"].ConnectionString
);
attachmentFilePath = server.MapPath(
ConfigurationManager.ConnectionStrings["ATTACHMENTFILEPATH"].ConnectionString
);
messageFilePath = server.MapPath(
ConfigurationManager.ConnectionStrings["MESSAGEFILEPATH"].ConnectionString
);
messageShieldFilePath = server.MapPath(