Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
using (var stream = File.Create(fileName))
{
    response.GetResponseStream().CopyTo(stream);
}


Pleas help. Thanks in advance
Posted
Updated 16-Aug-18 2:27am

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
 
Share this answer
 
v2
Comments
Ron Beyer 10-Jan-14 0:21am    
It should be noted that this only works on VS2010 or greater. If he's using 2008 or 2005 he won't have that option.
srmohanr 10-Jan-14 0:28am    
Hi, I have VS 2010.

Thanks for your suggesstion.
Karthik_Mahalingam 10-Jan-14 0:41am    
Ron,
ya, u r rite..
can we add reference of Framework v4.0 dll to vs 2008 ??
Ron Beyer 10-Jan-14 0:49am    
No, there is more than just a "dll", its an entire framework and a different compiler.
Karthik_Mahalingam 10-Jan-14 0:54am    
Oh i see.
Now very less number of people are using vs 2008 i guess.
we are in vs 2013 now :)
Apologies - I know this is an old post, but as pointed out by ftosteve[^] (in a solution that may be deleted) ...
Quote:
And what if you have to target .NET2?
Changing the project to .NET4 is just cheating
...
This blog[^] from Sam Beauvois gives examples that will target frameworks < .NET 4.0
 
Share this answer
 
Comments
srmohanr 29-May-14 0:14am    
Thanks for your reply.
Richard MacCutchan 16-Aug-18 9:04am    
Gave the abuser a kick, needs to be flagged in Spam and Abuse forum.
CHill60 16-Aug-18 9:12am    
Done
And what if you have to target .NET2?
Changing the project to .NET4 is just cheating...
 
Share this answer
 
Comments
CHill60 28-May-14 10:53am    
Then don't use CopyTo! Does this mean that you have the same problem and would like an answer?
CHill60 29-May-14 5:34am    
You may not have noticed but I have posted an alternative solution for frameworks < 4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900