In your code you spend a lot of time setting up the different possible alternate file types to download, yet when it comes to actually setting the file type you hard code it to pdf ie:-
Response.ContentType = "Application/pdf";
instead of
Response.ContentType = type;
Hope this helps