Wednesday, December 29, 2010

Opening HTML Files in Sharepoint 2010

By default, Sharepoint 2010 is blocking the ability to open HTML, Flash, ...some types files directly from a document library. It download it instead of displaying it.

This can be changed in the browser file handling option. To change this option go to:

1. Central Admin\Application Management\Manage Web Applications.
2. Select General Settings for the specified web application
3. For Browser file handling, select permissive. The default is strict.

If we need to keep this option for security.
SharePoint 2010 put these types static in code, You need to create HTTPModule to remove attachment from its header. Example in code below:


public class FixHeaderModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreSendRequestHeaders += OnPreSendRequestHeaders;
}

public void Dispose()
{

}

void OnPreSendRequestHeaders(object sender, EventArgs e)
{
// modify the "Server" Http Header
if (HttpContext.Current.Request.Url.AbsolutePath.EndsWith(".htm")
HttpContext.Current.Request.Url.AbsolutePath.EndsWith(".html")
HttpContext.Current.Request.Url.AbsolutePath.EndsWith(".swf"))
HttpContext.Current.Response.Headers.Remove("Content-Disposition");
}
}

No comments: