// clear the current output content from the buffer Response.Clear(); // add the header that specifies Response.AddHeader("Content-Disposition", "filename=" + file.Name); // add the header that specifies the file size, so that the browser // can show the download progress Response.AddHeader("Content-Length", file.Length.ToString()); // specify that the response is a stream that cannot be read by the // client and must be downloaded
/*FileStream fs = file.Open(FileMode.Open);
BinaryReader br = new BinaryReader(fs);*/ string fileName = file.Name.ToLower(); int lastIndex = fileName.LastIndexOf("."); fileName = fileName.Substring(lastIndex); // 根据文件后缀指定文件的Mime类型 switch (fileName) { case ".ppt": Response.ContentType = "application/ppt"; break; case ".rm": Response.ContentType = "application/vnd.rn-realmedia"; break; case ".mp3": Response.ContentType = "audio/mpeg3"; break; case ".asf": Response.ContentType = "video/x-ms-asf"; break; case ".avi": Response.ContentType = "video/avi"; break; case ".wav": Response.ContentType = "audio/wav"; break; case ".mpg": Response.ContentType = "video/mpeg"; break; case ".mpeg": Response.ContentType = "video/mpeg"; break; case ".wma": Response.ContentType = "video/x-ms-wma"; break; default: Response.ContentType = "application/octet-stream"; break; } Response.Charset = "UTF-8"; // send the file stream to the client int length = (int) file.Length; /*Response.BinaryWrite(br.ReadBytes(length));*/ Response.WriteFile(file.FullName); // flush the execution of this page Response.End(); /*Response.Clear();*/ // stop the execution of this page /*br.Close(); fs.Close();*/
pdf 只要客户端装Acrobat就能用浏览器打开
rm 有real服务器
mpg mp3 有midea player 服务器
{
n=f.Extension.ToLower();
editname= m_CurrentDir+f.Name;
sURL=_url+m_CurrentDir+f.Name;
DownPath="<a href =\"./FileDownload.aspx?sPath="+editname+"\" target=\"_blank\">"+f.Name+"</a>";
FileKey ="";//"<a href =\"./FileKey.aspx?sPath="+editname+"\"><img src=\"images/filekey.gif\"></a>";
sb.Append("<tr><td><input type=\"CheckBox\" name=\"selectfiles\" value=\""+f.Name+"\"></td>");
switch(n)
{
case ".htm":
sb.Append("<td><img src=\"images/html.gif\"> " + DownPath + " \n<a href="+sURL+" target=\"_blank\"><img src=\"images/ie.gif\" width=16 height=16 border=0 alt=\"浏览\"></a> \n<a href=\"editfile.aspx?name="+editname+"&type=file\"><img src=\"images/edit.gif\" width=16 height=16 border=0 alt=\"编辑\"></a> \n "+FileKey+"</td>\n");
break;
case ".html":
sb.Append("<td><img src=\"images/html.gif\"> " + DownPath + " <a href="+sURL+" target=\"_blank\"><img src=\"images/ie.gif\" width=16 height=16 border=0 alt=\"浏览\"></a> <a href=\"editfile.aspx?name=" +editname+"&type=file\"><img src=\"images/edit.gif\" width=16 height=16 border=0 alt=\"编辑\"></a> \n "+FileKey+"</td>\n");
break; .................................
按不同的后缀名生成不同的样式就是啦
{
SongStoreInfo ssi;
int id; //歌曲ID
HttpCookie myCookie = new HttpCookie("CanRead");
myCookie = Request.Cookies["CanRead"];
//如果直接访问页面页面时
if (myCookie == null)
{
Response.Redirect("http://www.cwestc.com");
}
id = int.Parse( Request.Params["ID"]); SongStore ss = new SongStore();
ssi = ss.GetDetails(id);
Configuration.ModuleSettings settings = Configuration.ModuleConfig.GetSettings(); FileInfo file = new System.IO.FileInfo(settings.SongPhysicsPrefix + ssi.SongUrl);
// clear the current output content from the buffer
Response.Clear();
// add the header that specifies
Response.AddHeader("Content-Disposition", "filename=" + file.Name);
// add the header that specifies the file size, so that the browser
// can show the download progress
Response.AddHeader("Content-Length", file.Length.ToString());
// specify that the response is a stream that cannot be read by the
// client and must be downloaded
/*FileStream fs = file.Open(FileMode.Open);
BinaryReader br = new BinaryReader(fs);*/
string fileName = file.Name.ToLower();
int lastIndex = fileName.LastIndexOf(".");
fileName = fileName.Substring(lastIndex); // 根据文件后缀指定文件的Mime类型
switch (fileName)
{
case ".ppt":
Response.ContentType = "application/ppt";
break;
case ".rm":
Response.ContentType = "application/vnd.rn-realmedia";
break;
case ".mp3":
Response.ContentType = "audio/mpeg3";
break;
case ".asf":
Response.ContentType = "video/x-ms-asf";
break;
case ".avi":
Response.ContentType = "video/avi";
break;
case ".wav":
Response.ContentType = "audio/wav";
break;
case ".mpg":
Response.ContentType = "video/mpeg";
break;
case ".mpeg":
Response.ContentType = "video/mpeg";
break;
case ".wma":
Response.ContentType = "video/x-ms-wma";
break;
default:
Response.ContentType = "application/octet-stream";
break;
} Response.Charset = "UTF-8"; // send the file stream to the client
int length = (int) file.Length;
/*Response.BinaryWrite(br.ReadBytes(length));*/
Response.WriteFile(file.FullName);
// flush the execution of this page
Response.End();
/*Response.Clear();*/
// stop the execution of this page
/*br.Close();
fs.Close();*/
gasover(无尽) 讲的好像是直接下载的,并不是在线浏览的吧,我也遇到在线浏览的困惑,不同文件类型如何调用指定软件打开啊