从服务器下载文件! 高分求助! 在线等 在本地机器的WEB页里有一个TEXTBOX 在其内输入本地磁盘路径,点击BUTTON 可以下载服务器上指定文件当然,你已经具备这个权限!如何才能做到?请高手指教 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在点击事件里写Response.Clear();FileStream fileStream=new FileStream(Server.MapPath("123.doc"),FileMode.Open);long fileSize = fileStream.Length; Context.Response.ContentType="application/msword"; //Response.AddHeader("Content-Disposition", "inline;FileName=123.doc");Context.Response.AddHeader("Content-Length",fileSize.ToString()); byte[] fileBuffer=new byte[fileSize]; fileStream.Read(fileBuffer, 0, (int)fileSize); Context.Response.BinaryWrite(fileBuffer); Context.Response.End(); 我下载要到TEXTBOX指定的路径! 而且你的filestream后面也没有用啊 调用xcopy吧 哈哈 用WebClient也行 直接用流也行 string path = 路径;System.IO.FileInfo file = new System.IO.FileInfo(path);Response.Clear();Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(file.Name));Response.AddHeader("Content-Length", file.Length.ToString());Response.ContentType = "application/octet-stream";Response.WriteFile(file.FullName);Response.End(); Response.Clear();FileStream fileStream=new FileStream(TextBoxID.Text,FileMode.Open);long fileSize = fileStream.Length; Context.Response.ContentType="application/msword"; //Response.AddHeader("Content-Disposition", "inline;FileName=123.doc");Context.Response.AddHeader("Content-Length",fileSize.ToString()); byte[] fileBuffer=new byte[fileSize]; fileStream.Read(fileBuffer, 0, (int)fileSize); Context.Response.BinaryWrite(fileBuffer); Context.Response.End(); 工程要实现的是一个WEB版的VSS,一个有管理权限的用户,可以和DB连接,取到一些文件,CHECK到ADMIN的机器上,同时他又作为服务器,许多终端用户,连接到他的机器上,把ADMIN 机器上的文件下载到终端客户的机器上进行修改.现在代码里能取到DB服务器端的文件,以前设计是直接把要修改的文件COPY到ADMIN机器上的另外一个文件夹,作为备份,现在客户要求DOWNLOAD到终端机器修改.然后再CHECKIN. 实际上这样就可以了啊,只要URL的重定向而已。string patch = Request.ApplicationPath + this.TextBox1.Text;Response.Redirect(patch);TextBox1.Text;里面要输入文件的相对路径,例如,文件在虚拟目录的/download/file.rar在TextBox1.Text就必须输入/download/file.rar才能下载,问题是这样的话就没什么安全性了,只要知道URL谁都可以下载。 求Js的 在线客服.... 怎么处理数据库中的null字段 想把日期格式"dd\MM\yyyy"用正则表达式替换成"yyyy\MM\dd" js 调服务器按钮 断点调试走了俩次 asp.net高手帮忙啊!!!!!!!!! Session_End事件到底什么时候执行,谁能说明白呀,讨论一下 页面提交后刷新页面数据又提交 Highcharts 显示不了数据问 请教:为何Asp.net网站会自己弹出用户名密码输入框? 求大神帮忙!vs2012,vs2015中文怎么识别不了! 求教:汉字列如何运用 ASP.NET2.0数据绑定
FileStream fileStream=new FileStream(Server.MapPath("123.doc"),FileMode.Open);
long fileSize = fileStream.Length;
Context.Response.ContentType="application/msword";
//Response.AddHeader("Content-Disposition", "inline;FileName=123.doc");
Context.Response.AddHeader("Content-Length",fileSize.ToString());
byte[] fileBuffer=new byte[fileSize];
fileStream.Read(fileBuffer, 0, (int)fileSize);
Context.Response.BinaryWrite(fileBuffer);
Context.Response.End();
System.IO.FileInfo file = new System.IO.FileInfo(path);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(file.Name));
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
FileStream fileStream=new FileStream(TextBoxID.Text,FileMode.Open);
long fileSize = fileStream.Length;
Context.Response.ContentType="application/msword";
//Response.AddHeader("Content-Disposition", "inline;FileName=123.doc");
Context.Response.AddHeader("Content-Length",fileSize.ToString());
byte[] fileBuffer=new byte[fileSize];
fileStream.Read(fileBuffer, 0, (int)fileSize);
Context.Response.BinaryWrite(fileBuffer);
Context.Response.End();
Response.Redirect(patch);TextBox1.Text;里面要输入文件的相对路径,例如,文件在虚拟目录的/download/file.rar
在TextBox1.Text就必须输入/download/file.rar才能下载,问题是这样的话就没什么安全性了,只要知道URL谁都可以下载。