使用相对URI作为XmlDataProvider的源 [英] Using relative URI as XmlDataProvider's Source

查看:181
本文介绍了使用相对URI作为XmlDataProvider的源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆