Search code examples
c#comboboxstreamreader

url in StreamReader


when i use this code,i can see text file in the folder That named like one of combobox item.

and when i change this @"C:\xampp\htdocs\c\" to http://localhost:81/c/ is not work and show this error

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

Additional information: URI formats are not supported.

what can i do ?

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(); 

sorry for my bad english :(


Solution

  • You need to use WebClient to read files from server ;

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