pls tel me how to Download files from DB using WPF(xbap)app in c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alister7
    New Member
    • Mar 2008
    • 2

    pls tel me how to Download files from DB using WPF(xbap)app in c#

    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
Working...