简体   繁体   English

从 OpenFileDialog 获取文件输入

[英]Taking file input from OpenFileDialog

I looked around for an answer to this and couldn't find anything.我环顾四周寻找答案,但找不到任何东西。 All I need to do is take an input from a text file with multiple lines selected from an OpenFileDialog box.我需要做的就是从一个文本文件中获取一个输入,该文件从 OpenFileDialog 框中选择了多行。 Here's a selection from my code:这是我的代码中的一个选择:

if (theDialog.ShowDialog() == DialogResult.OK)
        {
            try
            {
                if ((myStream = theDialog.OpenFile()) != null)
                {
                    using (myStream)
                    {
                        //I need this to take input given from OpenFileDialog

                        
                        this.read_display.Text = input;
                    }
                }
            }

I'm probably just overlooking something really obvious, but I'm not sure.我可能只是忽略了一些非常明显的东西,但我不确定。

If you want to get the text from stream , you can create a StreamReader instance and call method ReadToEnd() .如果要从stream获取文本,可以创建StreamReader实例并调用方法ReadToEnd()

string input;
using (StreamReader sr = new StreamReader(myStream))
{
    input = sr.ReadToEnd());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM