나는 다운로드 버튼을 누르면 SQL Server 테이블의 내용이 CSV 파일로 다운로드되는 다운로드 기능을 포함해야하는 프로젝트가 있습니다.SQL Server 테이블의 내용을 다운로드하고 내용을 CSV 파일에 저장 하시겠습니까?
내가 할 수있는 방법이 있습니까?
Characters
이라는 표의 내용이 csv 파일로 다운로드됩니다. 내가 아는 것은 내가 쿼리 Select* from Characters
을 사용하고 있지만 그것을 구현하는 방법을 모른다.
protected void btnDownload_Click(object sender, EventArgs e)
{
string fileName = string.Empty;
string filepath = Request.MapPath("~/Uploads");// this needs to be changed with the SQL query, but I do not know how to implement it
string downloadFileName = "Attendance.zip";
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=" + downloadFileName);
using (ZipFile zip = new ZipFile())
{
foreach (GridView row in gvFiles.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("chkSelect");
if (cb != null && cb.Checked)
{
fileName = (row.FindControl("lblFileName") as Label).Text;
zip.AddFile(Server.MapPath(Path.Combine(filepath, fileName)), "");
}
}
zip.Save(Response.OutputStream);
}
SQL Server 2008을 사용하고 있습니다. – Mark20