悬赏分:10 浏览:158 次
我用<a href='../<%# Eval("url") %>'>下载</a>做个下载的功能
现在问题是 如果是图片或者.txt文件的话 它会直接在另一个浏览器窗口内打开
我想统一成弹出提示下载的对话框 该么样改啊?
但是我又不想做成按钮点击 ?
|
你愿意做成把文件的内容写到数据库的吗?
用这个控件: <asp:FileUpload ID="FileUpload" runat="server" Width="437px" /> //In model.FileName = this.FileUpload.FileName; model.FileContent = this.FileUpload.FileBytes; model.FileType = this.FileUpload.PostedFile.ContentType; //Out 在把文件名给展现出来的旁边多个按钮 protected void lbtnFile_Click(object sender, EventArgs e) { InformInfo model = _facade.GetModel(Convert.ToInt32(this.lblId.Text)); Response.Buffer = true; Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(model.FileName)); Response.AddHeader("Content-Type", model.FileType); Response.BinaryWrite(model.FileContent); Response.End(); } <div onclick=\"OpenObject('" + Server.UrlEncode(URL) + "')\"><a>" + FileName + "</a></div> private void openFile() { string FilePath = Server.MapPath(FileURL); FileInfo fi = new FileInfo(FilePath); FileStream fs = new FileStream(FilePath, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); Response.Clear(); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fi.Name, System.Text.Encoding.UTF8).Replace("+", " ")); Response.BinaryWrite(bytes); Response.End(); } openFile()可以在页面回调加以区别后调用 |
|
2个月前 AndyFish : 。。。。。 被屏蔽了 “<div onclick=\"OpenObject('" + Server.UrlEncode(FileName) + "'," + isFile + ")\"><a>" + FileName + "</a></div>” |