私のチャット プログラムでは、他のユーザーにファイルを送信する必要がありますが、問題があります。Visual Studio でファイルを送信しようとすると、指定されたパスの形式がサポートされていないという例外が表示されます。
private void button3_Click(object sender, EventArgs e)
{
Stream myStream = null;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "A:\\";
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer).ToString();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
using (myStream)
{
byte[] bytes = File.ReadAllBytes(openFileDialog1.ToString());
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error:"+ ex.Message);
}
}
}
助けてください。