Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Visual studio项目目录问题_C#_Directory - Fatal编程技术网

C# Visual studio项目目录问题

C# Visual studio项目目录问题,c#,directory,C#,Directory,我正在写一个文本文件夹,它在我的项目中的一个文件夹中,但我似乎无法在不写绝对完整路径的情况下到达它,因为它在我的计算机上,这在这台计算机上很好,但当我想把它带到其他地方时,我无法得到它,因为驱动器不同等等 这是我用来将其发布到右边目录的行的屏幕截图 我试图访问的文件位于名为AdminAccount的文件夹中,名为User.txt。正如您可以从注释目录链接中看到的,它可以作为直接路径工作,但是当我尝试使用目录字符串时,它不起作用 有人帮我解决这个问题吗?我试过各种方法,我试过做 private

我正在写一个文本文件夹,它在我的项目中的一个文件夹中,但我似乎无法在不写绝对完整路径的情况下到达它,因为它在我的计算机上,这在这台计算机上很好,但当我想把它带到其他地方时,我无法得到它,因为驱动器不同等等

这是我用来将其发布到右边目录的行的屏幕截图

我试图访问的文件位于名为AdminAccount的文件夹中,名为User.txt。正如您可以从注释目录链接中看到的,它可以作为直接路径工作,但是当我尝试使用目录字符串时,它不起作用

有人帮我解决这个问题吗?我试过各种方法,我试过做

private string[] getLines = System.IO.File.ReadAllLines(@"\AdminAccount\User.txt");
private string[] getLines = System.IO.File.ReadAllLines(@"..\AdminAccount\User.txt");

没有乐趣。

您只需将“User.txt”文件的属性“Copy to Output Directory”设置为“Copy all ways”“Copy if newer”

现在你可以读下面的几行了

string[] getLines = File.ReadAllLines(
                 Path.Combine(Application.StartupPath, "AdminAccount", "User.txt"));

您只需将“User.txt”文件的属性“Copy to Output Directory”设置为“Copy allways”或“Copy if newer”

现在你可以读下面的几行了

string[] getLines = File.ReadAllLines(
                 Path.Combine(Application.StartupPath, "AdminAccount", "User.txt"));
你可以用

string rootPath = Environment.CurrentDirectory;
string filePath = Path.Combine(rootPath,@"..\..\AdminAccount\User.txt");
private string[] getLines = System.IO.File.ReadAllLines(@filePath);
。\
用于访问层次结构中的顶级文件夹。您可以继续添加
。\
以在层次结构中向上移动

例:

新路径将返回
C:\Users\Documents\visualstudio 2010\Projects\Test\Test\admincount\User.txt
您可以使用

string rootPath = Environment.CurrentDirectory;
string filePath = Path.Combine(rootPath,@"..\..\AdminAccount\User.txt");
private string[] getLines = System.IO.File.ReadAllLines(@filePath);
。\
用于访问层次结构中的顶级文件夹。您可以继续添加
。\
以在层次结构中向上移动

例:

新路径将返回
C:\Users\Documents\visualstudio 2010\Projects\Test\Test\admincount\User.txt

您当前的文件夹是什么?我知道你在哪一行上面写的文件?你当前的文件夹是什么?我知道你是从哪一个文件在上面写的?很好的解释。非常感谢。谢谢你的帮助!很好的解释。非常感谢。谢谢你的帮助!