0

I have problem with open new format documents Microsoft Office (docx, xlsx etc). I develop my project using ASP NET MVC.

I wrote new method:

[HttpGet]
[AllowAnonymous]
public ActionResult DownloadFileNew(Guid Id)
{
    FileTable fileTable = _DocumentService.GetFile(Id);

    HttpResponseBase response = ControllerContext.HttpContext.Response;
    response.ContentType = fileTable.ContentType;
    response.AppendHeader("Content-Disposition", String.Format("attachment;filename={0}", fileTable.FileName));

    MemoryStream ms = new MemoryStream(fileTable.Data);
    FileStreamResult document = new FileStreamResult(ms, fileTable.ContentType);

    document.FileStream.Seek(0, SeekOrigin.Begin);
    document.FileStream.CopyTo(response.OutputStream, (int)document.FileStream.Length);

    response.Flush();
    return new EmptyResult();
}

But don't work with new formats, only old format (doc, xls etc).

When I try open document I take error message: "Excel web app cannot open this document ..."

Log file:

  • Metro library failure: ShipAssert location: (0) condition:
    StackTrace: at uls.native.dll:
    (sig=35ebf2aa-983a-4c4a-a61b-a0d5e84ac5d0|2|uls.native.pdb,
    offset=1CD84) at xlsrv.dll:
    (sig=0beeafb2-5166-41c2-91f8-14cd1cedff75|2|xlsrv.pdb, offset=E7D801) at xlsrv.dll: (offset=E7CF26) at xlsrv.dll: (offset=5C2C8D) at
    xlsrv.dll: (offset=E249F2) at xlsrv.dll: (offset=E0FD6A) at
    xlsrv.dll: (offset=E0DFEE) at xlsrv.dll: (offset=DE0D20) at
    xlsrv.dll: (offset=DD7D14) at xlsrv.dll: (offset=DDC413) at
    xlsrv.dll: (offset=DD931F) at xlsrv.dll: (offset=DE0C28) at
    xlsrv.dll: (offset=1D9A6A) at xlsrv.dll: (offset=1D9B03) at
    xlsrv.dll: (offset=569A13) Watson bucket parameters: Uninitialized
    ULS, ULSShipAssert12, 2oxu, 15.0.4569.0 Data collection is not
    enabled for tag '2oxu' in the configuration or configuration file not available. Not reporting to Watson Metro library failure
    (0x80cb4204):
krlzlx
  • 5,752
  • 14
  • 47
  • 55

1 Answers1

1

Not sure what the ContentType you are using, but it has to be

For docx files

 Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"

For doc files

Response.ContentType = "application/ms-word"

List of all mime types here

Community
  • 1
  • 1
Kiru
  • 3,489
  • 1
  • 25
  • 46