473,382 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 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
Mar 13 '08 #1
0 1016

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

Similar topics

8
by: Tina | last post by:
While ASP.Net is migrating toward more robust presentation by using things like AJAX I am wondering if ClickOnce will errode a lot of ASP.Net presence in Corporate Applications. I've been reading...
1
by: khubieb | last post by:
Situation: We have to connect to a 3rd party XML Web Service outside our LAN by adding a WCF Service Reference to a simple console application Problem: When attempting to invoke any of the...
5
by: dgk | last post by:
From what I've been reading, an XBap application could be really good for a place like mine where everyone will have a PC that has framework 3 loaded and runs IE. The app is downloaded from a...
1
by: DNB | last post by:
WPF Browser Application VS ASP.Net Web Site We will be soon developing our new Web based project. We are still thinking should we use XBAP/WPF (XAML Browser Application) or regular ASP.Net Web...
0
by: Marek Kolesar | last post by:
Hi all i have a big problem with simple program wpf browser apliacation(xbap) app had only 1 label in grind where is loaded datatime from DB:) ( very easy sql comand )
3
by: =?Utf-8?B?SXpvcmljaA==?= | last post by:
I observed that WCF client running inside Full Trust mode XBAP application can't read byte array over 16384. If return result is bigger than that size, then client simply get null or Nothing in VB...
0
by: =?Utf-8?B?RGFyS293?= | last post by:
Hello all. Been struggling with this. I have a WCF service in IIS using a basicHttpBinding configured like this: <binding name="basicBinding"> <security mode="TransportCredentialOnly">...
5
by: developing | last post by:
My project is to port a .net desktop app (c#) to the web. Of course, I am going with asp.net since I can reuse most of the libraries and business logic. Problems come up with the GUI part. Is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.