以下代码为本人在一Silverlight程序中访问Web端配置文件的代码:
private void GetLoadNeed()
{
// 项目名称读取配置文件
WebClient wcConfigXml = new WebClient();
wcConfigXml.OpenReadCompleted += new OpenReadCompletedEventHandler(wcConfigXml_OpenReadCompleted);
wcConfigXml.OpenReadAsync(new Uri(System.Windows.Browser.HtmlPage.Document.DocumentUri,
"ConfigXml/AppGISConfig.xml"));
} private void wcConfigXml_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
try
{
using (Stream s = e.Result)
{
XDocument doc = XDocument.Load(s); //需要引用System.Xml.Linq if (doc.Root != null)
{
XElement xElement = doc.Root.Element("AppGIS");
if (xElement != null)
{
XElement element = xElement.Element("ProjectName");
if (element != null)
{
string projectName = element.Value;
}
}
}
}
}
catch
{
}
}