邮件表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();
} }
}
}
我用以下方法实现批量下载,只能下载第一个附件:
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();
} }
}
}
解决方案 »
- |ZYCWPF| WPF中写控件样式的时候,有没有办法像HTML的CSS写如 Grid Button{Margin5 5 5 5} 谢谢
- C#怎么监视某些特定文件被读取
- c#中如何引用加密的mssql存储过程
- 小妹求教!DataTable里应用SQL语句!
- WPF怎么在按钮的图片下方加入文字
- VS2005的安装问题,MSDN安装后不能用,提示...
- 新手提问:如何手工在c#net中连接数据库?
- 还要麻烦思归老哥一下或者其他人了。处理一串字符串的问题了
- 分享个代码,多个StreamWriter同步写入
- 多个窗体中如何显示同一个控件?
- DesignSurface如何让设计器响应键盘和鼠标指令呢?
- 關心報表設計器的朋友進入(C/S和B/S結構)
是否就构成批次下载的意思呢?