邮件表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();
                        }                    }
                }
}