User287566428 posted
Hey guys,
I am doing a request to this controller:
[ResponseType(typeof(Book))]
public async Task<IHttpActionResult> PostBook(Book book)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
string path = "C:\\Users\\af-costa\\Desktop\\TEST.docx";
var stream = new MemoryStream();
db.Books.Add(book);
await db.SaveChangesAsync();
// New code:
// Load author name
db.Entry(book).Reference(x => x.author).Load();
var dto = new BookDTO()
{
Id = book.Id,
Title = book.Title,
AuthorName = book.author.name
};
Table customTable = createTable(book.author.name, book.Title);
stream = createDocument(customTable);
return CreatedAtRoute("DefaultApi", new { id = book.Id }, dto);
}
the createDocument retrives me a memoryStream, i basicly need to download the file on the stream that i get from the openXml, in this method:
private void createDocument(Table customTable)
{
var stream = new MemoryStream();
// Create a Wordprocessing document.
using (WordprocessingDocument package = WordprocessingDocument.Create("Test1", WordprocessingDocumentType.Document))
{
// Add a new main document part.
package.AddMainDocumentPart();
// Create the Document DOM.
package.MainDocumentPart.Document =
new Document(
new Body(
new Paragraph(
new Run(
new Table(customTable)))));
// Save changes to the main document part.
package.MainDocumentPart.Document.Save();
}
stream.Seek(0, SeekOrigin.Begin);
}
i don't know very well how can i download that file, basicly i want to create a document with a table, and download it when the user performs a request to
that access point, any help?