读书人

◆C#实现批量上载

发布时间: 2012-12-21 12:03:49 作者: rapoo

◆C#实现批量下载◆
邮件表EmailDB中,邮件的附件以二进制流的形式保存在Files(image 类型)字段中,在页面中要实现勾选邮件的标题批量下载邮件的附件到指定文件夹,如何实现??!!
我用以下方法实现批量下载,只能下载第一个附件:

protected void btDownLoad_Click(object sender, EventArgs e)
{
string _ID = "";
foreach (GridViewRow gv in GridView1.Rows)
{
CheckBox cb = (CheckBox)gv.FindControl("CheckBox1");
if (cb.Checked)
{
int index = gv.RowIndex;
DataKey key = this.GridView1.DataKeys[index];//获取主键
Int64 GVID = Convert.ToInt64(key.Values["ID"]);
_ID += GVID.ToString() + ",";
}
}
if (_ID == "")
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "click", "alert('请选择要下载的报告!')", true);
}
else
{
int count = _ID.Split(',').Length - 1;
string[] AID = new string[count];
AID = _ID.Split(',');
for (int i = 0; i < count; i++)
{
ProductDocuments doc = new ProductDocuments();
Int64 ID = Convert.ToInt64(AID[i].Trim());


doc = _org.GetDcoumentInfo(ID);
if (string.IsNullOrEmpty(doc.FileType))
if (doc.FileType.ToString() == "")
{
Response.Write("<script>alert('没有附件!')</script>");
}
else
{
string filename = doc.ID + "." + doc.FileType;
filename = HandleFileName(filename);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.AddHeader("Content-Disposition",
String.Format("attachment;filename={0}", filename));
Byte[] buffer = (byte[])doc.Article;
Response.OutputStream.Write(buffer, 0, buffer.Length);
Response.Flush();
Response.End();
}

}


}
}


[最优解释]
UP
[其他解释]
顶一个。
[其他解释]
up
[其他解释]
帮顶,顺便看下我多少分了
[其他解释]
关注

[其他解释]
up
[其他解释]
原po若将该method()放在loop里
是否就构成批次下载的意思呢?
[其他解释]
关注中
[其他解释]
mark
[其他解释]
Up
[其他解释]
没有解决,自己顶!
[其他解释]
我也遇到这问题了,同求
[其他解释]
该回复于2011-04-25 09:21:06被版主删除
[其他解释]
求同……
[其他解释]
求解。。。

读书人网 >C#

热点推荐