Sign up ×
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));

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;
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
Per, I'm new in both Asp.Net & Sharepoint. I already have a .js file registered for my WebPart, but I couldn't understand how I must include the code above: should I create a function with that, how I would run this code, etc. Can you help me with this? – tcbrazil Jan 24 at 0:07

Your Answer


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.