this.Accessories.InnerHtml = "<a href=<%=FileDownload(FileUpload/" + ntmbulletin.FileUpload + "%>>" + ntmbulletin.FileUpload + "</a>";
解决方案 »
- 软考的数据库系统工程师
- 同一页面中有一个表单和一个gridview,如何点击gridview中行的任意位置,将行的ID值传入到表单中?
- 关于框架跳转问题 急
- 我在本地调试的没问题,可是把页面和程序都放到服务器上后,Session老是失效,几乎是几秒钟就失效了.这是怎么回事呀?
- StringBuilder builder = new StringBuilder(); Using 怎么写?
- VS2008注册用户时的密码问题
- 这个怎么处理一下 ?
- 没分了,DataTable 在页面输出
- 如何将TEXTBOX的值逐个添加到LISTBOX服务器控件中???
- 请问怎样使启动窗口象ShowModalDialog函数显示的窗口一样?
- 软件测试有哪些测试工具?
- 发邮件
this.Accessories.InnerHtml = "<a href=<%=FileDownload(FileUpload/" + ntmbulletin.FileUpload + "%>>" + ntmbulletin.FileUpload + "</a>";
我想输出到前台 实现下载 但是发现有文本文件下载不了的问题呀 所以就想用流
能不能在此基础上指点
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
this.Accessories.InnerHtml = "<a href=<%=FileDownload(FileUpload/" + ntmbulletin.FileUpload + "%>>" + ntmbulletin.FileUpload + "</a>";
必须要得到怎么调用你哪个方法
哪个方法我早知道了
可以目前我的思路怎么调用呢
高手 高手 AJAX调用的时候老出错
1:this.Accessories.InnerHtml = "<a href=\"#\" onclick=\"javacript:FileDownload('" + ntmbulletin.FileUpload + "')\">" + ntmbulletin.FileUpload + "</a>";2:function FileDownload(filename)
{
PageService.FileDown(filename,TrueOrFalse,OnFailded);
}3: [WebMethod(EnableSession = true)]
public bool FileDown(string fileName)
{
string serFile = HttpContext.Current.Server.MapPath("~/FileUpload/") + fileName; // 服务器上存放文件的地址
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Type", "text/plain");
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
HttpContext.Current.Response.WriteFile(serFile); // 将文件以流的形式传输
HttpContext.Current.Response.End();
return true;
}
老提示 调用失败终止进程
是不是AJAX不能处理这块
可我不用AJAX交互 用什么呢
{
//禁止缓存
Response.Cache.SetCacheability(HttpCacheability.NoCache);
if (!IsPostBack)
{ string wuliname = Request["wuliname"].ToString();
string path = Request["wuliname"].ToString();
string leibie="";
if (Request["leibie"] != null)
{
leibie = Request["leibie"].ToString();
} string a = UPLOADNAME + "/" + leibie + "/" + wuliname;
string luojiname = Request["luojiming"].ToString();
string workpath = Server.MapPath(a);
System.IO.FileInfo file = new System.IO.FileInfo(workpath); if (file.Exists)
{
Response.Clear();//清除缓冲区流中的所有内容输出
Response.ClearHeaders();//清除缓冲区流中的所有头,不知道为什么,不写这句会显示错误页面
Response.ContentType = "application/octet-stream";//设置输出类型,应用于所有文件
Response.Charset = "utf-8";
//Response.ContentType = "application/x-zip-compressed";
//将 HTTP 头添加到输出流
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Request.ContentEncoding.GetBytes(luojiname)));//一定要写,不写出错
Response.TransmitFile(a);//以上将指定的文件直接写入 HTTP 内容输出流。
Response.End();//将当前所有缓冲的输出发送到客户端,这句户有时候会出错,可以尝试把这句话放在整个函数的最后一行。
}
else
{
AlertClose(up1, "不存在该文件,下载失败", true);
}
ScriptManager.RegisterStartupScript(up1, typeof(UpdatePanel), "initRadioChecked", "window.close();", true);
}
}这是我原来做过的一个项目中的写法 前台 什么都没有。
this.Accessories.InnerHtml = "<a href='??'>" + ntmbulletin.FileUpload + "<a>";
{
string filepath = Server.MapPath("File/") + filename;
if (File.Exists(filepath))
{
try
{
FileStream s = File.OpenRead(filepath);
return ConvertStreamToByteBuffer(s);
}
catch
{
return new byte[0];
}
}
else
{
return new byte[0];
}
}
}