المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : checked file download from gridview



C# Programming
03-31-2009, 03:40 PM
i have one gridview the source code of gridview is given below.




























download file--%>





















c# code:

protected void btnDownload_click(object sender, EventArgs e)
{
foreach (GridViewRow gvr in GridView1.Rows)
{

CheckBox cb = (CheckBox)gvr.FindControl("check");
if (cb.Checked)
{
string filepath = gvr.Cells[14].Text;
DownloadFile(filepath);
}
}
}

protected void DownloadFile(string filepath)
{
System.IO.Stream iStream = null;
byte[] buffer = new byte[10000];
int length;
long dataToRead;

string filename = System.IO.Path.GetFileName(filepath);
try
{
iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
dataToRead = iStream.Length;
Response.ContentType = "application/octet-stream";
Response.AddHeader("content-Disposition", "attachment;filename=" + filename);
while (dataToRead > 0)
{
if (Response.IsClientConnected)
{
length = iStream.Read(buffer, 0, 10000);
Response.OutputStream.Write(buffer, 0, length);
Response.Flush();
buffer = new byte[10000];
dataToRead = dataToRead - length;
}
else
{
dataToRead = -1;
}
}
}
catch (Exception ex)
{
Response.Write("Error:" + ex.Message);
}
finally
{
if (iStream != null)
{
iStream.Close();
}
}
}

error message::Error:Could not find file 'C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\675676'.
any body give me the solution
thankyou in advance