views:

116

answers:

2

I have a file in the website and i m trying to send this file to windows application using the Response.BinaryWrite (getContent)( Where getContent is the byte array having the file which I need to send) vis HTTP post method only. Also I m adding a Header and Content-Type as application/octet-stream in the Response.

Now while reading the (httpWebResponse) response in the stream at client side(windows application) all the things (header + content-type + file + some extra bytes) are getting added. so when I try to read the file in stream it cannot be loaded since the content has chnged Is there any way to separate the file from rest contents present in the response object.. How sahll I save this file in directory

+1  A: 

Use System.Net.WebClient.DownloadData or DownloadFile method instead.

Mehrdad Afshari
A: 

What language / version are you using?

If you are using a reasonably up-to-date version of C# you can use the WebClient class, and its DownloadFile method

ZombieSheep
As far as I remember, WebClient has *always* been in the .NET BCL.
Mehrdad Afshari
Thanks,We could download the file using this but requirement is to send file via Response object(may be as attachment) using HTTP POST method and extract it on the client side(windows app) using httpWebREsponse class.Is there any way to implement this.I am using .net 2.0 framework with VS2005
Fair enough - I couldn't remember when I first saw it. :)
ZombieSheep
@Mugdha: You can parse the HTTP response and ignore the headers with HttpWebResponse. However, I can't see any reason not using WebClient. What's exactly the requirement that `WebClient` can't satisfy?
Mehrdad Afshari