Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Force MP3 Download

Reply
 
Old 06-01-2009   #1 (permalink)
Goldenrate


 
 

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 SpecsSystem Spec
Old 06-02-2009   #2 (permalink)
Colbert Zhou [MSFT]


 
 

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 SpecsSystem Spec
Old 06-02-2009   #3 (permalink)
Jesse Houwing


 
 

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,
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 SpecsSystem Spec
Old 06-02-2009   #4 (permalink)
Goldenrate


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46