Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Oct 13, 2016 10:48 am

Hi there,

I'm using WebApi ApiController endpoint to get a document.
I can't use .SaveToFile, since it expects HttpResponse rather than HttpResponseMessage available on ApiController.

I'm trying to use this approach, but it doesn't work either:
//Save doc file.
var stream = new MemoryStream();
// processing the stream.
document.SaveToStream(stream, FileFormat.Docx);

var result = new HttpResponseMessage(System.Net.HttpStatusCode.OK)
{
Content = new ByteArrayContent(stream.GetBuffer())
};
result.Content.Headers.ContentDisposition =
new ContentDispositionHeaderValue("attachment")
{
FileName = "CSample.docx"
};
result.Content.Headers.ContentType =
new MediaTypeHeaderValue("application/octet-stream");

return result;

Thanks in advance

diogo@resident.uk.com
 
Posts: 2
Joined: Thu Oct 13, 2016 9:30 am

Fri Oct 14, 2016 3:00 am

Hi,

Thanks for your inquiry.
Please use the method ToArray() to convert the stream to byte.
Code: Select all
        HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
        {
          Content = new ByteArrayContent(stream.ToArray())
        };

If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue Oct 18, 2016 8:57 am

Hi,

Has your issue been resolved ? Could you please give us some feedback at your convenience ?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Oct 21, 2016 1:12 pm

Yes, thank you

diogo@resident.uk.com
 
Posts: 2
Joined: Thu Oct 13, 2016 9:30 am

Mon Oct 24, 2016 1:20 am

Hi,

Thanks for your feedback.
Please feel free to contact us if there is any question. We will be happy to help you.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc