Naresh Babu Gopavaram

Naresh Babu Gopavaram

  • 1.4k
  • 248
  • 247.9k

Generate HTTpResponse message from FileStream in .Net4.0 .

Sep 29 2014 5:19 AM
 Hi All
I have used the following code to generate HTMLResponseMessage in WCF Rest Service with .Net 4.5 . But I need to generate the same in .Net 4.0 version. I could not able to find the solution.
Can any one help me on this 
 
public static HttpResponseMessage GetFile()
{
string file=@"C:/test.docx"; 
var rv = new HttpResponseMessage(HttpStatusCode.OK);
var stream = new FileStream(file, FileMode.Open, FileAccess.Read);
rv.Content = new StreamContent(stream);
rv.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
return rv;
}
 
Thanks in advance