Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need to download a file from a virtual directory when clicking on a button in sharepoint.

I've tried this:

page.Response.ContentType = "text/vcard";
page.Response.AppendHeader("Content-Disposition", "attachment; filename=" + path);
page.Response.TransmitFile(page.Server.MapPath("~/vcf/" + path));
page.Response.Flush();
page.Response.End();

The problem with this is that I can download the file, but after downloading, I can't do anything on the page. I guess that's the Response.End(), but deleting that line doesn't work because he'll add text to my downloaded file...

Is there an easy solution to this? Or another (working) solution is always welcome...

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Change the web part (or whatever) that's rendering the button to include the following javascript into the page:

_spOriginalFormAction = document.forms[0].action;
_spSuppressFormOnSubmitWrapper=true;
share|improve this answer
    
OMG, you're my hero... been looking for this all day! Thanks a lot! –  Ruben Herman May 14 '12 at 13:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.