问题描述
我必须使用c#从文本文件创建一个字符串。
这部分对任何人来说都很容易。
问题在于:
我的项目文件夹为:Property_Utility
在此文件夹中,我有WindowsFormsApplication3文件夹,1 .suo文件和1 .sln解决方案文件。
在WindowsFormsApplication3文件夹中,我有我的设计和cs文件。
现在,我已将我的.txt文件放在此文件夹中。
Environment.CurrentDirectory读取位置〜\ WindowsFormsApplication3 \ bin\debug
所以我可以从调试文件夹中读取文件,但不能从WindowsFormsApplication3文件夹中读取。
我无法手动给出一个特定的绝对路径,因为该项目打算在多台机器上运行。
请提供如何直接读取WindowsFormsApplication3文件夹位置的建议。
Th anks,
Vivek
Hi,
I have to create a string from a text file using c#.
This part for anyone is typically very easy.
The problem lies here:
I have my Project Folder as: Property_Utility
Inside this folder, I have WindowsFormsApplication3 Folder, 1 .suo file and 1 .sln solution file.
In WindowsFormsApplication3 folder, I have my design and cs files.
Now, I have placed my .txt files in this folder.
Environment.CurrentDirectory read the location "~\WindowsFormsApplication3\bin\debug"
So I can read the file, from debug folder but not from WindowsFormsApplication3 folder.
I cannot manually give a particular absolute path as the project is intended to run on multiple machines.
Please give suggestions how to read WindowsFormsApplication3 folder location directly.
Thanks,
Vivek
推荐答案
<location path="MyFiles">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
这将允许在运行时访问该文件夹。
This will allow the access to this folder at runtime.
string codefolderpath = Directory.GetParent(Directory.GetParent(Environment.CurrentDirectory).ToString()).ToString()
;
感谢所有人的帮助。
在这个开玩笑......我研究了Site.Map和Directory并结合了更多的东西。
非常感谢。
Thanks all for help.
In this jest... I studied about Site.Map and Directory and couple more things.
Thanks a lot.
这篇关于ASP.NET C#WebForm当前目录问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!