如何从解决方案资源管理器中提供文件路径 [英] how to give file path from solution explorer

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

问题描述



我正在制作一个wpf应用程序。

因为我正在读一些存在于计算机物理位置的文件。



所以在我的应用程序中我写了文件的路径,如



C:\ Users \shorts \Desktop\\\
nn \\ \\ bbb \sss \swa.txt



但如果我将我的应用程序用于其他电脑,则会出错。



然后我将所有文件添加到解决方案资源管理器中



并给出了路径..\files\swa.txt



它也不起作用。



请给我一些建议。

Hi,
I am making an wpf application.
in that i am reading some files that exist in physical location of computer.

so in my application i wrote path for file like

C:\Users\shorts\Desktop\nnn\bbb\sss\swa.txt

but if i am using my application into other pc it gives error.

then i added all file into solution explorer

and gave path "..\files\swa.txt"

its also not working.

please suggest me something.

推荐答案

您可以使用 Application。 StartupPath,然后在Windows应用程序中构建相关的应用程序路径。
You can use Application.StartupPath and then build the relative application path in a windows application.


此处的补救措施情况(可能)是修复您在运行应用程序的所有计算机上写入的文件路径,因此它们与上下文无关。



编写文件相对于 .NET环境引用的特殊文件夹之一.SpecialFolder枚举是一种安全的方法[ ^ ]。
The remedy in this situation is (probably) to fix the file paths you write to on all machines running your Application so they are "context independent."

Writing files relative to one of the Special Folders referenced by .NET's Environment.SpecialFolder enumeration is a safe way to go [^].


只需创建文件夹并将所有文件放在应用程序中的该文件夹中

然后使用它将起作用
just make folder and put all files in that folder in your application
then use it will works


这篇关于如何从解决方案资源管理器中提供文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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