470,833 Members | 1,455 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

HTTPcontext.current returns null in WPF Browser Application .. please help

hi every1

im trying to download a music file from the database SQLserver.which i upload in the database.. The Code below works fine in wen i create a new project of an ASP.Net web application..m using VS 2008

but it gives me an error wen i run the same code in WPF broser APplication(xbap).. it throws an error saying Null reference encountered. the line of error is HTTPcontext context=HTTPcontext.Current;
it goes in the else part of the loop and returns "Current is Null" ..how do i set current to !null Please help me.
below is the code

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);

string SqlSelect = "select * from Audi where Song_name='" + txtsname.Text + "'";

DataSet ds = new DataSet();
SqlCommand mycommand = new SqlCommand(SqlSelect,con);
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.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);
System.Windows.Forms.MessageBox.Show("Current is null");

Mar 13 '08 #1
0 2104

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Luis Esteban Valencia Muñoz | last post: by
reply views Thread by Aaron Morton | last post: by
8 posts views Thread by eric | last post: by
3 posts views Thread by Madhur | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.