0

嗨,我正在使用,

  FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read);

从我在调试目录中定义但没有成功的临时文件夹中读取文件。使用此代码,我可以仅从 Debug-Folder 读取文件。谁能帮忙!

这是我的代码

private void button_click(object sender, RoutedEventArgs e)
    {
        string activeDirectory = System.Windows.Forms.Application.StartupPath + "\\Temp\\";

        string[] files = Directory.GetFiles(activeDirectory);
        try
        {
            foreach (string fileName in files.Select(f => f.Substring(activeDirectory.Length)))
            {
                FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            }
        }
        catch()
        {}
    }
4

1 回答 1

0

如果您正在运行调试版本,那么 System.Windows.Forms.Application.StartupPath将返回调试文件夹的路径,因为您的 exe 存在于该文件夹中。

于 2012-09-25T12:48:14.847 回答