如何为文件夹提供相对路径? [英] how to give relative path for a folder?

查看:374
本文介绍了如何为文件夹提供相对路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我需要为解决方案中的文件夹提供一个相对路径

thsiis完整路径: c:\users\priya.sasidharan\documents\visual studio 2010 \Projects\ProjectAddIn3 \ProjectAddIn3 \Templates\Data.xml

我这样给了@〜\ Templates\Data.xml但它不是wrking。它显示以下错误

''C:\ Users \ priya.sasidharan \Documents \〜\ProjectAddIn3 \ProjectAddIn3 \Templates\Data.xml''不能找到

Hi i need to give a relative path for the folder in the solution
thsiis the complete path:c:\users\priya.sasidharan\documents\visual studio 2010\Projects\ProjectAddIn3\ProjectAddIn3\Templates\Data.xml
I gave like this@"~\Templates\Data.xml but its not wrking.it is showing the following error
''C:\Users\priya.sasidharan\Documents\~\ProjectAddIn3\ProjectAddIn3\Templates\Data.xml'' could not be found

推荐答案

你好Spriyanair,



相对路径强制执行你所知道的(在运行时的代码中)你在哪里执行。

在运行时,相对路径将与正在运行的可执行文件的路径连接。



例如在Visual Studio中使用相对路径在调试模式下运行或在发布模式下运行时会有不同的行为不同的文件夹。



从你的问题看来你的可执行文件似乎在文件夹中: C:\ Users \ priya.sasidharan.AMEX \ Document \

是您希望将 @〜\Templates\Data.xml添加到的相对路径?



干杯,

Edo
Hello Spriyanair,

Relative path enforces that you know (in the code on runtime) where are you executing from.
During runtime, a relative path will be concatenated with the path of the executable running.

For example using relative path in visual studio will act differently when running in debug mode or in release mode since they operate from different folders.

From your question is seems that your executable is in the folder: C:\Users\priya.sasidharan.AMEX\Documents\
is that the relative path you want your @"~\Templates\Data.xml" to be added to?

Cheers,
Edo


这篇关于如何为文件夹提供相对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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