1: using System;
2: using System.Reflection;
3: using System.Web;
4: using System.Web.UI;
5: using System.Web.UI.HtmlControls;
6:
7: namespace MartinOnDotNet.Support
8: {
9: /// <summary>
10: /// Force OfficeDocuments to be treated as normal DMS Assets
11: /// </summary>
12: public class OfficeDocumentFixModule : IHttpModule
13: {
14:
15: /// <summary>
16: /// Initializes a module and prepares it to handle requests.
17: /// </summary>
18: /// <param name="context">An <see cref="T:System.Web.HttpApplication"/> that provides access to the methods, properties, and events common to all application objects within an ASP.NET application</param>
19: public void Init(HttpApplication context)
20: {
21: if (context == null) throw new ArgumentNullException("context");
22: context.PreRequestHandlerExecute += new EventHandler(OnPreRequestHandlerExecute);
23: }
24:
25: private void OnPreRequestHandlerExecute(object sender, EventArgs e)
26: {
27: HttpContext current = HttpContext.Current;
28: if (current == null
29: || current.Handler == null
30: || current.Request == null
31: || !current.Request.Url.AbsolutePath.EndsWith("/workarea/edit.aspx", StringComparison.OrdinalIgnoreCase)) return;
32:
33: Page page = current.Handler as Page;
34: page.PreInit += new EventHandler(OnPreInit);
35:
36: }
37:
38: /// <summary>
39: /// Always return false regardless of actual value
40: /// </summary>
41: public class AlwaysFalseHiddenField : System.Web.UI.HtmlControls.HtmlInputHidden
42: {
43: /// <summary>
44: /// Gets or sets the value associated with the <see cref="T:System.Web.UI.HtmlControls.HtmlInputControl"/> control.
45: /// </summary>
46: /// <value></value>
47: /// <returns>
48: /// The value associated with the <see cref="T:System.Web.UI.HtmlControls.HtmlInputControl"/>.
49: /// </returns>
50: public override string Value
51: {
52: get
53: {
54: return "false";
55: }
56: set
57: {
58: base.Value = value;
59: }
60: }
61: }
62:
63:
64:
65: /// <summary>
66: /// Called when the Page load event fires
67: /// </summary>
68: /// <param name="sender">The sender.</param>
69: /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
70: private void OnPreInit(object sender, EventArgs e)
71: {
72: Page page = sender as Page;
73: if (page == null) return;
74: PropertyInfo officeDocProperty = page.GetType().GetProperty("isOfficeDoc", BindingFlags.Instance | BindingFlags.NonPublic);
75: if (officeDocProperty == null) return;
76:
77: HtmlInputHidden hil = officeDocProperty.GetValue(page, null) as HtmlInputHidden;
78: AlwaysFalseHiddenField fhil = new AlwaysFalseHiddenField();
79: fhil.ID = hil.ID;
80: fhil.Name = hil.Name;
81: fhil.Value="false";
82: page.PreRenderComplete += (s, ea) =>
83: {
84: hil.Value = "false";
85: };
86: officeDocProperty.SetValue(page, fhil, null);
87:
88: }
89:
90:
91: /// <summary>
92: /// Disposes of the resources (other than memory) used by the module that implements <see cref="T:System.Web.IHttpModule"/>.
93: /// </summary>
94: public void Dispose()
95: {
96: //throw new NotImplementedException();
97: }
98:
99:
100: }
101: }