Geeks With Blogs
Sean Rhone

I recently convert a ASP.NET 1.1 web app to 2.0 and included MasterPages to define a consistent look, menu etc but ran into a problem with the <meta name="DownloadOptions" content="noopen"/> code. Our site allows users to export data to Excel and text files and also upload pictures and some other file types. Problem is you need to have the <meta name="DownloadOptions" content="noopen"/> tag in the  html <header> which exist in the MasterPage and as you know content pages can not contain top level html content.

For those of you who don't know what <meta name="DownloadOptions" content="noopen"/> does, it modifes the ShowDialog popup and removes the "Open" button so the user only see's the "Save" and "Cancel;" button.

So the problem is, how do I allow users to export to Excel and text files (without the option of "Open" and upload the other files. The way I decided to go is I created a custom attribute class called "ShowDialogNoOpen" and used this attribute on every class in my application that allows exporting files (I don't have an instance where I export and allow the used to upload in one class). Next I put code in the MasterPage file that is called during the Page_Load event that checks if the current "this.Page" has this attribute. If the class does have this attribute I wrote a method that emits a new meta tag. The code is pasted below that shows this.

This is the custom attribute class
public class ShowDiaglogNoOpen: Attribute
{public bool ShowOpen()
return false;}



In the MasterPage I created a method that looks like
private void CheckForAttribute()
     MemberInfo  info = this.Page.GetType();
     // Instead of gettting ALL attributes I only want to search for one
     object[] attr = info.GetCustomAttributes(typeof(ShowDialogNoOpen),true);
     // Check if anything was returned
     if(attr != null && attr.GetLength(0) >0)

 private void EnitMetaTag()
    // New class for creating meta tags
    HtmlMeta meta = new HtmlMeta():
    //Use the Name property to specify the meta tag we want to use
    meta.Name = "DownloadOptions";
    //Add the Content param
    meta.Content = "noopen";
    // add this new meta tag to the page


So, now to stop allowing users the "open" button all I have to do is add [ShowDialogNoOpen] to the class that uses this masterpage and all is well.

Posted on Monday, February 2, 2009 6:25 PM | Back to top

Comments on this post: Meta tag DownloadOptions

# re: Meta tag DownloadOptions
Requesting Gravatar...
good article my friend.
Left by Ashish patel. on Feb 09, 2009 11:04 AM

# re: Meta tag DownloadOptions
Requesting Gravatar...
Does firefox support a meta tag with downloadoptions with values of nosave,noopen?

I have tried but not working in mozilla.
Left by Eashwar V on Jun 30, 2011 7:46 AM

# re: Meta tag DownloadOptions
Requesting Gravatar...
I have tried this option and it did work well on my end. - Morgan Exteriors
Left by John Roberts on Sep 20, 2016 11:29 PM

Your comment:
 (will show your gravatar)

Copyright © Sean Rhone | Powered by: