我有一些代碼可以從網站下載文本文件。當請求的文件不存在時,我的應用程序會下載包含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