从网站下载pdf,word(任何文件)的代码 [英] code for downloading pdf,word,(any files) from a website

查看:104
本文介绍了从网站下载pdf,word(任何文件)的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai

iam使用asp.net,c#(网站位置:文件系统)开发网站.
谁能帮我...


我想下载搜索后显示在列表框中的文件.
我已经完成了从服务器中搜索文件的操作.

我使用的代码如下:

hai

iam developing a website using asp.net,c#(web location:file system ).
can any one help me...


i want to download the file that is displayed in the list box after the search.
i have done the searching of file from the server.

and the code i used is as follows:

resultsList.Items.Clear();
string s = "",s1=""; //to get the file name
// string files = "";
string filename = '*' + fileNameTextBox.Text + '*';
DirectoryInfo MyDir;
ArrayList CellarList = new ArrayList();
MyDir = new DirectoryInfo(Server.MapPath("files/"));
string path = (Server.MapPath("files/"));
//FileInfo[] MyFiles = MyDir.GetFiles("*.*");
string[] fileList = System.IO.Directory.GetFiles(path, filename);

foreach (string file in fileList)
{
  s = file.ToString();
  s1 = s.Replace(path, "");
  resultsList.Items.Add(s1);
}



所以请帮忙......
在此先感谢



so plz help....
thanks in advance

推荐答案

1.您可以简单地使用window.open(fileurl); javascript中的命令.如果浏览器支持,则它将直接打开文件,否则将显示下载"对话框.


或者您可以使用适当的下载按钮,即


1. You Can Simpally Use window.open(fileurl); command in javascript. it will directly open a file if browser support other wise shows download dialog box.


or you can use a proper download button i.e


string sFilename;
sFilename = Server.MapPath("todown.doc");
byte[] btFile = System.IO.File.ReadAllBytes(sFilename);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;filename=" + sFilename + "");
Response.OutputStream.Write(btFile, 0, btFile.Length);
Response.End();


这篇关于从网站下载pdf,word(任何文件)的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆