MAHDI.TX MAHDI.TX - 1 year ago 186
C# Question

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

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

sorry for my bad english :(

Answer Source

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();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download