url 在 StreamReader 中

url in StreamReader

当我使用此代码时,我可以在文件夹中看到文本文件,其名称类似于组合框项目之一。

当我将此 @"C:\xampp\htdocs\c\" 更改为 http://localhost:81/c/ 不起作用并显示此错误

An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll

Additional information: URI formats are not supported.

我能做什么?

private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

    richTextBox1.Text = toolStripComboBox1.SelectedItem.ToString();
                string rich =  toolStripComboBox1.SelectedItem.ToString();
                richTextBox1.Text= rich += ".txt";

           StreamReader rd = new StreamReader(@"C:\xampp\htdocs\c\" + rich);
                       richTextBox1.Text = rd.ReadToEnd();     
                           rd.Close(); 

对不起我的英语不好:(

您需要使用WebClient从服务器读取文件;

WebClient client = new WebClient();
Stream stream = client.OpenRead("http://localhost:81/c/"+ rich);
StreamReader reader = new StreamReader(stream);
string str= reader.ReadToEnd();

我将此代码添加到 Nihat Mert 答案及其工作

 richTextBox1.Text = str;