如何将特定列中的gridview行下载到文件路径中指定的行 [英] How to download a gridview rows in a particular column to specified in a filepath

查看:81
本文介绍了如何将特定列中的gridview行下载到文件路径中指定的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表值:-


album_name Genre_name艺术家价格

旧式岩石亚当110.00
永远不能说再见爵士大卫290.00

在此我只想下载(专辑名称)的特定列...

请帮我解决这个问题...


类文件:-

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:-

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:-

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

stream = new FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);


错误显示访问被拒绝..


the error has showing access is denied..

推荐答案

请按照我的提示进行操作
从asp.net中的GridView行下载文件4.0 [ ^ ]
Please follow my Tip
File Download from the GridView rows in asp.net 4.0[^]


立即,我不得不说它失败了,因为您的FileStream指向的是目录而不是文件. br/>
Off hand I would have to say that it''s failing because your FileStream is pointing to a directory not a file.

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



在询问下一个错误之前,可能是因为fileName被设置为"System.Data.DataSet"之类的东西



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


这篇关于如何将特定列中的gridview行下载到文件路径中指定的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆