我有一些代码可以从网站下载文本文件。当请求的文件不存在时,我的应用程序会下载包含html内容的文本文件。我需要过滤这个html内容(如果请求的文件不存在,不应该下载包含html内容的文本文件),并且只需要下载具有正确内容的文本文件。以下是我的代码。使用C下载文件#
string FilePath = @"C:\TextFiles\" + FileName + String.Format("{0:00000}", i) + ".TXT";
Directory.CreateDirectory(Path.GetDirectoryName(FilePath));
//MessageBox.Show(FilePath);
using (FileStream download = new FileStream(FilePath, FileMode.Create))
{
Stream stream = clientx.GetResponse().GetResponseStream();
while ((read = stream.Read(buffer, 0, buffer.Length)) != 0)
{
download.Write(buffer, 0, read);
}
}
请指点
如果找不到文件,您需要显示一个html页面吗? – giftcv
不,html页面不应该下载。实际上它不是一个html页面。 HTML内容的文本文件 – Kevin