我使用Asp.net 3.5 C#如何将System.Xml.XmlDocument类型添加到和应用程序状态
我有一个XmlDocument添加到我的应用程序的状态,这样每次我的应用程序犯规上访问XML文件我的文件系统,我会在Global.asax.cs中的的Application_Start()函数中添加此
我为加入这一系统状态:
protected void Application_Start(Object sender, EventArgs e)
{
string filePath = Server.MapPath("<path to my XML FILE>");
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlTickerDoc.Load(filePath);
}
finally
{
HttpContext.Current.Application["xmlDoc"] = xmlDoc;
}
}
在此代码我尝试加载XML文件,并如果该文件没有加载由于任何问题,那么我想要一个空的XmlDocument。
我访问此XmlDocument的是:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc = HttpContext.Current.Application["xmlDoc"];
错误我得到的,而构建是
不能键入 '对象' 隐式转换为 'System.Xml.XmlDocument'。存在明确的转换
那么如何将HttpContext.Current.Application [“xmlDoc”]变量指定为System.Xml.XmlDocument?
如果您有其他问题,请编辑您的问题/添加一个单独的问题。不要把它作为答案的一部分。 – 2010-02-09 08:14:34