i need a code to download a music file(.wav) in WPF Browser Applications. below is the code that m trying...
private void downloadfile()
{
string connectionstring = @"Data Source=01HW107887\SQLEXPRESS;AttachDbFilename=D:\m ainproject\Database\prjectDatabase.mdf;Integrated Security=True"; //ConfigurationManager.ConnectionStrings["prjectDatabaseConnectionString"].ToString();
SqlConnection con = new SqlConnection(connectionstring);
// mycommand.Connection = con;
string SqlSelect = "select * from Audi where Song_name='" + txtsname.Text + "'";
DataSet ds = new DataSet();
SqlCommand mycommand = new SqlCommand(SqlSelect,con);
con.Open();
SqlDataAdapter da = new SqlDataAdapter(mycommand);
da.Fill(ds, "Audi");
string Filename;
if (ds != null)
{
string FileType = ds.Tables["Audi"].Rows[0]["ContentType"].ToString();
byte[] FileContent = (byte[])ds.Tables["Audi"].Rows[0]["song"];
Filename = ds.Tables["Audi"].Rows[0]["Song_name"].ToString();
HttpContext context = HttpContext.Current;
if (context != null)
{
context.Response.ClearContent();
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + Filename + "." + FileType);
context.Response.AddHeader("Content-Length", FileContent.Length.ToString());
context.Response.ContentType = FileType;
context.Response.OutputStream.Write(FileContent, 0, FileContent.Length);
context.Response.End();
}
else
{
System.Windows.Forms.MessageBox.Show("Current is null");
}
con.Close();
}
}
the code enters the else part of the loop and returns current is null
why is it so?? m i missing anything? pls help
Alister