从Web目录中获取文件名 - 来自服务

时间:2014-07-27 11:08:44

标签: c# wcf filenames

您能告诉我如何从服务级别的Web目录中获取文件名。我有一个包装服务。在里面我试图获取文件名。我无法找到解决方案。

1 个答案:

答案 0 :(得分:0)

如果我正确理解了这个问题,我可能没有这个问题,因为你不是太具体,听起来就像获取FTP列表一样简单:

using System;
using System.IO;
using System.Net;
using System.Text;

namespace Examples.System.Net
{
    public class WebRequestGetExample
    {
        public static void Main ()
        {
            // Get the object used to communicate with the server.
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/");
            request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

            // This example assumes the FTP site uses anonymous logon.
            request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();

            Stream responseStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(responseStream);
            Console.WriteLine(reader.ReadToEnd());

            Console.WriteLine("Directory List Complete, status {0}", response.StatusDescription);

            reader.Close();
            response.Close();
        }
    }
}