我正在尝试获取位于网址中的所有文件。 当您在浏览器中访问URL时,所有文件都被列出,所以我想我也可以在我的控制台程序中打印这些文件。
显然,我下面的代码不起作用并抛出System.ArgumentException "URI formats are not supported."
。或者是否真的可以在使用C#的控制台应用程序中实现这一点?
class Program
{
public static void Main(string[] args)
{
foreach (string filename in Directory.GetFiles(@"http://mywebsite.files/", "*.*"))
{
Console.WriteLine(filename);
}
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
答案 0 :(得分:2)
答案 1 :(得分:0)
也许你应该读一下ftp-protocol的用法。您尝试解决问题的方式很可能无法解决。
答案 2 :(得分:0)
如果您有FTP访问权限,则可以使用FtpWebRequest课程。以下是http://msdn.microsoft.com/en-us/library/ms229716.aspx
的示例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();
}
}
答案 3 :(得分:0)
我已经编写了一些代码,可以在 IIS http站点下获取所有路径信息,如果允许目录列表,最后可以通过以下方式进行操作:
var text = $("<div/>").html($("#editor").data("kendoEditor").value()).text();
可以自行定制帮助程序代码,正则表达式,或更改为使用html解析器):
public function hookCreateAccountForm ()
{
return $this->display(__FILE__, 'myfield.tpl');
}