'System.IO.Stream'不包含'CopyTo'的定义 [英] 'System.IO.Stream' does not contain a definition for 'CopyTo'

查看:310
本文介绍了'System.IO.Stream'不包含'CopyTo'的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我在C#控制台应用程序中收到错误



Hi I am getting the error in my C# Console application

'System.IO.Stream' does not contain a definition for 'CopyTo' and no extension method 'CopyTo' accepting a first argument of type 'System.IO.Stream' could be found (are you missing a using directive or an assembly reference?)





这是我的代码



This is my code

HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
using (var stream = File.Create(fileName))
{
    response.GetResponseStream().CopyTo(stream);
}





请求帮助。在此先感谢



Pleas help. Thanks in advance

推荐答案

您好mohan



CopyTo 仅适用于dot net Framework 4.0及以上版本。



参考: System.IO CopyTo [ ^ ]



请将您的项目版本更改为 Framework 4.0

右键单击项目 - > 属性 - > 申请标签 - > 目标框架 - >选择 .Net Framework 4.0
Hi mohan

CopyTo is available in dot net Framework 4.0 and above only.

Reference:System.IO CopyTo[^]

Please change your project version to Framework 4.0.
Right Click Project -> Properties - > Application Tab - > Target FrameWork -> select .Net Framework 4.0


道歉 - 我知道这是一个旧帖子,但正如 ftosteve [ ^ ](在可能被删除的解决方案中)...
Apologies - I know this is an old post, but as pointed out by ftosteve[^] (in a solution that may be deleted) ...
引用:

如果你必须以.NET2为目标怎么办?

将项目更改为.NET4只是作弊

And what if you have to target .NET2?
Changing the project to .NET4 is just cheating

...

博客 [ ^ 来自Sam Beauvois的例子给出了针对框架的例子< .NET 4.0

...
This blog[^] from Sam Beauvois gives examples that will target frameworks < .NET 4.0


如果你必须以.NET2为目标怎么办?

将项目更改为.NET4只是作弊......
And what if you have to target .NET2?
Changing the project to .NET4 is just cheating...


这篇关于'System.IO.Stream'不包含'CopyTo'的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆