![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Force MP3 Download Hi Everyone, I'm trying to force My application to download MP3 file instead of playing it in browser. I used this asp cod to create download image /******************// <asp:ImageButton ID="ibDownload" runat="server" style="border:0;" ImageUrl="~/DesktopModules/ASPvia_AudioDownload/images/Download.jpg" onclick="ibDownload_Click" /> </div> /*********************/ When clicked it calls /***********************/ protected void ibDownload_Click(object sender, ImageClickEventArgs e) { string f = String.Concat("Portals\\0\\",GetUserIDForProductOwner(),"\\",GetMediaFileName()); string filePath = Server.MapPath(f); Response.Clear(); Response.AddHeader("content-disposition", "attachment; filename=" + GetMediaFileName()); Response.ContentType = "application/audio/mpeg"; Response.WriteFile(filePath); Response.End(); } /*******************************/ GetMediaFileName() - retrieve the file name from the database. f - stores the virtual directory of the file. I've checked the code time and time again and found nothing wrong. Does anybody know what am I doing wrong? Thanks, |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Force MP3 Download Hello David, I cannot see any wrong parts in the code. Actually, I also use your codes and write a simple test project in my side. It works fine. When I click the download button, the browser pops a File Download dialog to ask me to download the mp3 file. You can get my project from my http://cid-c2e0d62e8a095a30.skydrive.../WebApplicatio nTest.zip I think the issue may also be related to the Web browser. I test on both of IE and FireFox. What browser are you using? And if you test with my project, do you still encounter the same issue? Best regards, Ji Zhou Microsoft Online Community Support Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@xxxxxx. ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/en-us/subs...#notifications. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Force MP3 Download Hello goldenrate, Quote: > Hi Everyone, > > I'm trying to force My application to download MP3 file instead of > playing it in browser. > > I used this asp cod to create download image > > /******************// > <asp:ImageButton ID="ibDownload" runat="server" style="border:0;" > > ImageUrl="~/DesktopModules/ASPvia_AudioDownload/images/Download.jpg" > onclick="ibDownload_Click" /> > </div> > /*********************/ > When clicked it calls > > /***********************/ > protected void ibDownload_Click(object sender, ImageClickEventArgs > e) > { > string f = > String.Concat("Portals\\0\\",GetUserIDForProductOwner(),"\\",GetMediaF > ileName()); > string filePath = Server.MapPath(f); > Response.Clear(); > Response.AddHeader("content-disposition", "attachment; > filename=" + GetMediaFileName()); > Response.ContentType = "application/audio/mpeg"; > Response.WriteFile(filePath); > Response.End(); > } > /*******************************/ > GetMediaFileName() - retrieve the file name from the database. f - > stores the virtual directory of the file. > > I've checked the code time and time again and found nothing wrong. > Does anybody know what am I doing wrong? > Thanks, that should give the browser an additional hint, it ins't supposed to stream the content to a player. -- Jesse Houwing jesse.houwing at sogeti.nl |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Force MP3 Download Thank you all for your help. Actually I was able to solve it. The problem, like in so many other error, is AJAX. I disabled it and it all work fine now. Cheers, ![]() "Jesse Houwing" <jesse.houwing@xxxxxx> wrote in message news:e5317a7e7800ce748cbb19241b9dec7@xxxxxx Quote: > Hello goldenrate, > Quote: >> Hi Everyone, >> >> I'm trying to force My application to download MP3 file instead of >> playing it in browser. >> >> I used this asp cod to create download image >> >> /******************// >> <asp:ImageButton ID="ibDownload" runat="server" style="border:0;" >> >> ImageUrl="~/DesktopModules/ASPvia_AudioDownload/images/Download.jpg" >> onclick="ibDownload_Click" /> >> </div> >> /*********************/ >> When clicked it calls >> >> /***********************/ >> protected void ibDownload_Click(object sender, ImageClickEventArgs >> e) >> { >> string f = >> String.Concat("Portals\\0\\",GetUserIDForProductOwner(),"\\",GetMediaF >> ileName()); >> string filePath = Server.MapPath(f); >> Response.Clear(); >> Response.AddHeader("content-disposition", "attachment; >> filename=" + GetMediaFileName()); >> Response.ContentType = "application/audio/mpeg"; >> Response.WriteFile(filePath); >> Response.End(); >> } >> /*******************************/ >> GetMediaFileName() - retrieve the file name from the database. f - >> stores the virtual directory of the file. >> >> I've checked the code time and time again and found nothing wrong. >> Does anybody know what am I doing wrong? >> Thanks, > It may sound stupid, but replace your original ContentType with > application/octet-stream that should give the browser an additional hint, > it ins't supposed to stream the content to a player. > > -- > Jesse Houwing > jesse.houwing at sogeti.nl > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Force PXE next boot | Vista installation & setup | |||
| n force????? | Graphic cards | |||
| Possible Fix: Microsoft Force Feedback 2 Joystick and the self center force disabling | Vista hardware & devices | |||
| Force SP1 installation | Windows Updates | |||
| G Force Go no Go! | Vista hardware & devices | |||