从服务器下载文件! 高分求助! 在线等 在本地机器的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谁都可以下载。 如何在IIS5.1中配置ASP.NET网站 请问DataList中的HyperLink如何传值 .NET(C#)ActiveX请教 html编辑器问题 小白问题!在线急求 推荐几本ASP.net 的入门书籍! js里怎么取select和checkboxlist的选择值 小型网络公司如何继续生存? 怎样在Update函数中得到Datagrid中修改后的数据 发布网站时生成的dll和编译时生成的不一致 求教:汉字列如何运用 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谁都可以下载。