Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
table value:-


album_name Genre_name artist price

legacy rock adam 110.00
never can say good bye jazz david 290.00

in this i want download only particular column of (album_name)...

Plz help me to solve this...


Class file:-
C#
public class download
{
	public download()
	{
		//
		// TODO: Add constructor logic here
		//
	}


    public static DataSet GetresourcePath()
    {
        SqlConnection con = new SqlConnection("Data Source=PRABAKARAN\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True");
        con.Open();            
        string sql = "select album_name from addcart";    
        SqlCommand command = new SqlCommand(sql, con);
        SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
        DataSet dataSet = new DataSet();
        dataAdapter.Fill(dataSet, "filePath");    

        return dataSet;
    }
}




default page:-
C#
try
{
    //string dbPath = null;
    DataSet path = download.GetresourcePath();
    //foreach (DataRow row in path.Tables[0].Rows)
    //{
    //    dbPath = string.Format("{0}", row[0]);
    //}

    string filePath = "C:\\Users\\prabakarans\\Downloads\\Albums";
    string fileName = path.ToString();
    Stream stream = null;
    stream = new FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
    long bytesToRead = stream.Length;
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("content-Disposition", "attachment; filename=" + fileName);
    while (bytesToRead > 0)
    {
        if (Response.IsClientConnected)
        {
            byte[] buffer = new Byte[10000];
            int length = stream.Read(buffer, 0, 10000);
            Response.OutputStream.Write(buffer, 0, length);
            Response.Flush();
            bytesToRead = bytesToRead - length;
        }
        else
        {
            bytesToRead = -1;
        }
    }
}
catch (Exception ex)
{
    ex.Message.ToString();
}



when am executing a program

in this line....
C#
stream = new FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);

the error has showing access is denied..
Posted
Updated 19-Apr-12 22:41pm
v2

Off hand I would have to say that it's failing because your FileStream is pointing to a directory not a file.

C#
string filePath = "C:\\Users\\prabakarans\\Downloads\\Albums";
                string fileName = path.ToString();
                Stream stream = null;
                stream = new FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);


And before you ask about the next error, it's probably because fileName is being set to something like "System.Data.DataSet"
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900