In my Web Application I need to give facility to the user to browse their FTP Location, as of File Browse of Asp.Net.
To do so, I have used OpenFileDialog
of Windows Forms. It works for any local location, but it does not work for any ftp location.
Below is my Code.
protected void BtnOpenFileDialog_Click(object sender, EventArgs e)
{
var t = new Thread(SelectFolder);
t.IsBackground = true;
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
private void SelectFolder()
{
Stream myStream = null;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "ftp://username:password@ftpidaddress/";
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = false;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
using (myStream)
{
// code to read the stream here.
}
}
}
catch (Exception ex)
{
// exception handing here
}
}
}
Please suggest me if I am doing anything wrong in it.. Or suggest me if any other ways to do so.