过路的帮俺看看,路过有分

WWWDJ1983 WWWDJ1983 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我数据库字段 "多附件上传地址" 中形式如下:
A:/aaa;B:/bbb;C:/ccc;
下载的时候怎么办?

public string FormatString(string str)
{
str = str.Replace(" ", "  ");
str = str.Replace("<", "<");
str = str.Replace(">", ">");
str = str.Replace('\n'.ToString(), "<br>");
return str;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Request["id"] != null)
{
int id = Convert.ToInt32(Request["id"]);//转换为数字,防止sql注入

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
conn.Open();
adr = "select 附件上传地址 from Mail WHERE 邮件编号 = " + id;
SqlCommand cmd = new SqlCommand(adr, conn);
string path = cmd.ExecuteScalar().ToString();
//取得路径
filepath = FormatString(path.ToString()).ToString().Trim();

string Temp_filename = FormatString(path.ToString()).ToString();
int pos = Temp_filename.LastIndexOf("\\") + 1;
filename = Temp_filename.Substring(pos, Temp_filename.Length - pos).ToString();
filename = HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(filename));

Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
FileStream fs = new FileStream(filepath, FileMode.Open);
long FileSize = fs.Length;
byte[] Buffer = new byte[(int)FileSize];
fs.Read(Buffer, 0, (int)fs.Length);
fs.Close();
Response.ContentType = "application/octe-stream";
Response.AddHeader("content-disposition", "attachment;filename=" + filename);
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.BinaryWrite(Buffer);
conn.Close();
}
}

我这个只能下载如:A:/aaa 这样形式的单个附件,请问我要怎么改?
拜谢答者~~
...全文
评论 40
收藏 已收藏
分享
返回顶部
WWWDJ1983
.NET社区 62,271 成员 668,968 内容