By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,307 Members | 1,518 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,307 IT Pros & Developers. It's quick & easy.

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

P: 2
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" 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
Share this question for a faster answer!
Share on Google+

Post your reply

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