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 connectionstrin g = @"Data Source=01HW1078 87\SQLEXPRESS;A ttachDbFilename =D:\mainproject \Database\prjec tDatabase.mdf;I ntegrated Security=True"; //ConfigurationMa nager.Connectio nStrings["prjectDatabase ConnectionStrin g"].ToString();
SqlConnection con = new SqlConnection(c onnectionstring );
// mycommand.Conne ction = con;
string SqlSelect = "select * from Audi where Song_name='" + txtsname.Text + "'";
DataSet ds = new DataSet();
SqlCommand mycommand = new SqlCommand(SqlS elect,con);
con.Open();
SqlDataAdapter da = new SqlDataAdapter( mycommand);
da.Fill(ds, "Audi");
string Filename;
if (ds != null)
{
string FileType = ds.Tables["Audi"].Rows[0]["ContentTyp e"].ToString();
byte[] FileContent = (byte[])ds.Tables["Audi"].Rows[0]["song"];
Filename = ds.Tables["Audi"].Rows[0]["Song_name"].ToString();
HttpContext context = HttpContext.Cur rent;
if (context != null)
{
context.Respons e.ClearContent( );
context.Respons e.AddHeader("Co ntent-Disposition", "attachment ; filename=" + Filename + "." + FileType);
context.Respons e.AddHeader("Co ntent-Length", FileContent.Len gth.ToString()) ;
context.Respons e.ContentType = FileType;
context.Respons e.OutputStream. Write(FileConte nt, 0, FileContent.Len gth);
context.Respons e.End();
}
else
{
System.Windows. Forms.MessageBo x.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
private void downloadfile()
{
string connectionstrin g = @"Data Source=01HW1078 87\SQLEXPRESS;A ttachDbFilename =D:\mainproject \Database\prjec tDatabase.mdf;I ntegrated Security=True"; //ConfigurationMa nager.Connectio nStrings["prjectDatabase ConnectionStrin g"].ToString();
SqlConnection con = new SqlConnection(c onnectionstring );
// mycommand.Conne ction = con;
string SqlSelect = "select * from Audi where Song_name='" + txtsname.Text + "'";
DataSet ds = new DataSet();
SqlCommand mycommand = new SqlCommand(SqlS elect,con);
con.Open();
SqlDataAdapter da = new SqlDataAdapter( mycommand);
da.Fill(ds, "Audi");
string Filename;
if (ds != null)
{
string FileType = ds.Tables["Audi"].Rows[0]["ContentTyp e"].ToString();
byte[] FileContent = (byte[])ds.Tables["Audi"].Rows[0]["song"];
Filename = ds.Tables["Audi"].Rows[0]["Song_name"].ToString();
HttpContext context = HttpContext.Cur rent;
if (context != null)
{
context.Respons e.ClearContent( );
context.Respons e.AddHeader("Co ntent-Disposition", "attachment ; filename=" + Filename + "." + FileType);
context.Respons e.AddHeader("Co ntent-Length", FileContent.Len gth.ToString()) ;
context.Respons e.ContentType = FileType;
context.Respons e.OutputStream. Write(FileConte nt, 0, FileContent.Len gth);
context.Respons e.End();
}
else
{
System.Windows. Forms.MessageBo x.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