I am setting the disposition of either inline
or attachment
based on users selection. It works but very intermittently. Once I select inline for the same file in the same browser, it works as expected. Once I switch to attachment, I don't get the desired results unless I close and reopen the browser. I do flush the context and clear it as well.
Here's the code I am using:
public void GetResult(ControllerContext context)
{
context.HttpContext.Response.Buffer = true;
context.HttpContext.Response.Clear();
context.HttpContext.Response.ContentType = ContentType;
ContentDisposition disposition = new ContentDisposition();
disposition.FileName = FileName;
disposition.Inline = this.ContentDispositionType == ContentDispositionType.Inline ? true : false;
context.HttpContext.Response.AddHeader("content-disposition", disposition.ToString());
context.HttpContext.Response.WriteFile(context.HttpContext.Server.MapPath(Path));
context.HttpContext.Response.Flush();
context.HttpContext.Response.End();
}