This sample uses a Gridview, with a HyperLink Field, to show how to simply create a song download list. In this sample, since it's set up just to quickly stream/play the files, the target file is '.m3u'.
To make it downloadable, change the extension to '.mp3' for your files. The only bad part about that, is most people's systems are setup to automatically run any filetype it recognizes, so it will try to play the song, even after the long MP3 download. You can prompt the users to right-click and choose the 'Save Target As' option.
Note, too, that here, I've not included the extension or the path in the database - just the filename. There's no really good reason I didn't include the extension. But this shows how to use the extension with the DataNavigateUrlFormatString of the Gridview. Also, by not hardcoding the path in the database, if you decide to move it to a different location later, you only need to change it in one place, instead of in every row of the table.
<%@ Page Language="VB" %> <html> <head> <title>Music Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Your_dbConnectionString %>" SelectCommand="SELECT [id], [Title], [Filename], [Genre], [Author] FROM [SongTest]"> </asp:SqlDataSource> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" /> <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" /> <asp:BoundField DataField="Genre" HeaderText="Genre" SortExpression="Genre" /> <asp:BoundField DataField="Author" HeaderText="Author" SortExpression="Author" /> <asp:HyperLinkField DataNavigateUrlFields="Filename" DataNavigateUrlFormatString="http://YourPath/{0}.m3u" DataTextField="Filename" DataTextFormatString="Get it Now" HeaderText="Download" Target="_blank" /> </Columns> </asp:GridView> </div> </form> </body> </html>
|
No responses found. Be the first to respond and make money from revenue sharing program.
|