使用相对URI作为XmlDataProvider的源 [英] Using relative URI as XmlDataProvider's Source
问题描述
在.NET中的XmlDataProvider
对象上设置Source
属性时,是否可以使用相对URI?我收到以下异常:
Is it possible to use a relative URI when setting the Source
property on an XmlDataProvider
object in .NET? I get the following exception:
IOException:System.IO.IOException: Cannot locate resource 'configuration.xml'.
当我使用绝对URI设置Source
属性时,一切都会按预期进行:
When I set the Source
property using an absolute URI, everything works as expected:
provider.Source = new Uri(@"C:\bin\Configuration.xml", UriKind.Absolute);
但是,当我尝试使用相对URI时,出现异常:
However when I try using a relative URI I get the exception:
provider.Source = new Uri(@"Configuration.xml", UriKind.Relative);
我的程序集都与配置文件位于同一目录中.怎么了?
My assemblies are all located in the same directory as the configuration file. What's wrong here?
推荐答案
尝试一下: FileInfo文件=新的FileInfo("configuration.xml"); provider.Source =新的System.Uri(file.FullName);
Try this: FileInfo file = new FileInfo("configuration.xml"); provider.Source = new System.Uri(file.FullName);
这篇关于使用相对URI作为XmlDataProvider的源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!