Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

serving up a wierd file extension to force a save dialogue

Status
Not open for further replies.

DarwinIT

Programmer
Apr 25, 2008
142
US
I want to give users the ability to save text files (and in the future - MD5). If I actually use a .txt extension, the data opens up in the browser without prompting for a save or open. If I use a different extension, I get a page not found error. In another website on a different server that extension worked just the way I wanted it to without any modifications, so I can only assume there is a setting in IIS that determines what file types will be processed and how. I tried adding my custom extension to the Mime types but that did not help (I did not stop either the website or the Application so perhaps that information is cached and won't show up without a refresh.
 
you need to set the cotenttype and a Content-Disposition header. here is an example using an HttpHandler to view pdfs
Code:
public class ViewReport : IHttpHandler
    {
        public void Process(HttpContext context)
        {
            byte[] report = GenerateReport();
            string fileName = GetFileName();
            var response = context.Response;
            response.ContentType = "application/pdf";
            response.AddHeader("Content-Disposition", "attachment;filename=" + fileName + ".pdf");
            response.BinaryWrite(report);
        }

        public bool ReUse { get { return false; } }
    }
"attachement" is the key. if this doesn't prompt for a save, try "inline" instead.
your content type would also be different. something like "text/txt".

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Thanks. What I was curious about though is why it works on one IIS server and not another one? There must be a setting in IIS to cause this??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top