Ftp FolderView文件在Asp.net中浏览C#

时间:2012-06-27 14:02:22

标签: c# ftp asp.net-4.0 filebrowse

在我的Web应用程序中,我需要为用户提供浏览其FTP位置的功能,从Asp.Net的文件浏览开始。

为此,我使用了OpenFileDialog的Windows窗体。它适用于任何本地位置,但它不适用于任何ftp位置。

以下是我的代码。

    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
            }
        }
    }

如果我做错了,请建议我.. 或者建议我是否有其他方法可以这样做。

0 个答案:

没有答案