我需要为我的应用程序使用 .NetFramework3.5,但是3.5CopyTo()
中WriteTo()
没有方法。3.5中的等效方法是什么?
当我使用 3.5 运行代码时,它会引发以下错误:
“System.IO.Stream”不包含“WriteTo”的定义,并且找不到接受“System.IO.Stream”类型的第一个参数的扩展方法“WriteTo”
这是代码:
int fileId = 1;
foreach (string uri in uriList)
{
request = (HttpWebRequest)WebRequest.Create (baseURL + uri);
request.Headers.Add ("X", authenticateStr);
request.Accept = "application/pdf";
request.Method = "GET";
webResponse = (HttpWebResponse)request.GetResponse();
using (MemoryStream ms = new MemoryStream())
using (FileStream outfile = new FileStream("document_", FileMode.Create)) {
webResponse.GetResponseStream().WriteTo(ms);
if (ms.Length > int.MaxValue) {
throw new NotSupportedException("Cannot write a file larger than 2GB.");
}
outfile.Write(ms.GetBuffer(), 0, (int)ms.Length);
}
}
Console.WriteLine("Done!");