i want to upload mp3 songs and also download it....
i got code from our partener site and it is help ful but when i click on upload button then it doesnt go to that click event so that code is not working....
plz help me its very urgent....
my code is:=
protected void mpsong_button_click(object sender, EventArgs e)
{
using (BinaryReader br = new BinaryReader(FileUpload1.PostedFile.InputStream))
{
byte[] bytes = br.ReadBytes((int)FileUpload1.PostedFile.InputStream.Length);
{
{
cmd.CommandText = "INSERT INTO DSActor.DTL_SONGS(SONG_NAME,SONG_EXTENSION,SONG_BINARY)" + " VALUES (@SONG_NAME,@SONG_EXTENSION,@SONG_BINARY)";
cmd.Parameters.AddWithValue("@SONG_NAME", Path.GetFileName(FileUpload1.PostedFile.FileName));
cmd.Parameters.AddWithValue("@SONG_EXTENSION", "audio/mpeg3");
cmd.Parameters.AddWithValue("@SONG_BINARY", bytes);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
Response.Redirect(Request.Url.AbsoluteUri);
}
my handler code is:=
using System;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
public class File : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
int TYPE_ID = int.Parse(context.Request.QueryString["TYPE_ID"]);
byte[] bytes;
string contentType;
//string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
String str = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
string name;
using (SqlConnection con = new SqlConnection(str))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select SONG_NAME, SONG_EXTENSION, SONG_BINARY from DSActor.DTL_SONGS where TYPE_ID=@Id";
cmd.Parameters.AddWithValue("@Id", TYPE_ID);
cmd.Connection = con;
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
bytes = (byte[])sdr["SONG_BINARY"];
contentType = sdr["SONG_EXTENSION"].ToString();
name = sdr["SONG_NAME"].ToString();
con.Close();
}
}
context.Response.Clear();
context.Response.Buffer = true;
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + name);
context.Response.ContentType = contentType;
context.Response.BinaryWrite(bytes);
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
and code of designing page(grid view code) is:=
<div id="tab3" class="tab_content">
<h2>Mp3 Songs</h2>
<div >
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="mpsong_button_click" />
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false" RowStyle-BackColor="#A1DCF2" Font-Names = "Arial" Font-Size = "10pt"
HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White">
<Columns>
<asp:BoundField DataField="Name" HeaderText="FileName" />
<asp:TemplateField>
<ItemTemplate>
<object type="application/x-shockwave-flash" data='dewplayer-vol.swf?mp3=File.ashx?Id=<%# Eval("TYPE_ID") %>'
width="240" height="20" id="dewplayer">
<param name="wmode" value="transparent" />
<param name="movie" value='dewplayer-vol.swf?mp3=File.ashx?Id=<%# Eval("TYPE_ID") %>'/>
</object>
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField DataNavigateUrlFields="Id" Text = "Download" DataNavigateUrlFormatString = "~/File.ashx?Id={0}" HeaderText="Download" />
</Columns>
</asp:GridView>
</div>
</div>
lz help me.
thnks in advance...