0

I'm using FileResult to show files in my web site as the following:

public ActionResult GetSwf(long id = 0)
{
    if (id <= 0) return null;
    Attachment attachment = Service.GetAttachmentById(id);
    if (attachment == null) return null;

    string filename = attachment.Name;
    string mimeType = "application/x-shockwave-flash";
    string absoluteFilePath = UploadedPaths.GetAbsolutePath(attachment.Path);

    return File(absoluteFilePath, mimeType, filename);
}

It doesn't work for the following tag and the browser is going to download file instead of show it!

<object type="application/x-shockwave-flash" width="220" height="166" data="File/GetSwf/1232" class="flash-object" data-name="ads-file"></object>

What's wrong, how can I fix it?

Mohammad Dayyan
  • 21,578
  • 41
  • 164
  • 232

1 Answers1

0

Eventually, I found the solution.
I had to change the action as the following:

public ActionResult GetSwf(long id = 0)
{
    if (id <= 0) return null;
    Attachment attachment = Service.GetAttachmentById(id);
    if (attachment == null) return null;

    string filename = attachment.Name;
    string mimeType = "application/x-shockwave-flash";
    string absoluteFilePath = UploadedPaths.GetAbsolutePath(attachment.Path);

    byte[] bytes = System.IO.File.ReadAllBytes(absoluteFilePath);
    return new FileContentResult(bytes, mimeType);
}
Mohammad Dayyan
  • 21,578
  • 41
  • 164
  • 232