当前位置:首页
开发技术指南» 文章正文
    引言:

    摘要: char* aa=new char[10]; aa[]="abc"; 怎么使aa[]="abcd";谢谢 ......
 ·郁闷    »显示摘要«
    摘要: 最近好不顺啊。。。。。顶了有分 ......


关于页面中点击下载和文件删除的问题

1、在下载页中,我点击下载按钮,要求打开一个新的页面,在新的页面打开时从文件夹里读取这个文件,然后关闭这个页面,就和没打开过一样,要求使用另存不能下载或打开这个文件,试了N次都没成,基本上我能找到的方法和我能想到的全试过了,还是不行。主要是下载那里我弄不好  
   
  2、文件的删除也是一样,在删除数据记录时要同时删除对应的文件,绝对路径什么的试过好多次了,还是不行!看看谁有这个能力帮帮我吧,谢谢大家先  
   
  我用的是C#.NET

NO.1   作者: ccwq

一.为什么要打开一个新页面呢?直接取文件在服务器的路径,然后写入WriterStream,直接Response给客户端就行了呀?  
  二.删除数据记录时,用FileInfo.Exists判断文件是否存在,是就删除不是就PASS  
   
 

NO.2   作者: fayewang

按1楼所述!本来网上很多此类文章了  
  1. DateTime   dt   =   DateTime.Now;  
  string   nowtime   =   dt.Year.ToString()+"-"+dt.Month.ToString()+"-"+dt.Day.ToString();  
  string   path   =   Server.MapPath("jiesuan\\huikuan"+   nowtime   +".txt");  
  System.IO.FileInfo   file   =   new   System.IO.FileInfo(path);  
   
  //   clear   the   current   output   content   from   the   buffer  
  Response.Clear();  
  //   add   the   header   that   specifies   the   default   filename   for   the   Download/SaveAs   dialog  
  Response.AddHeader("Content-Disposition",   "attachment;   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  
  Response.ContentType   =   "application/octet-stream";  
  //   send   the   file   stream   to   the   client  
  Response.WriteFile(file.FullName);  
  //   stop   the   execution   of   this   page  
  Response.End();  
  2.删除  
  string   SerFile   =   Server.MapPath(@"..\UpLoad\MatchFund.txt");  
  try  
  {  
  if(File.Exists(SerFile))  
  {  
  File.Delete(SerFile);  
  }  
  UpFile.PostedFile.SaveAs(Server.MapPath(@"..\UpLoad\MatchFund.txt"));  
  MessageInfo.Text   =   "上传成功!";  
  }  
  catch(Exception   ee)  
  {  
  MessageInfo.Text   =   "发生异常,请重新上传!错误信息内容为:"   +   ee.Message;  
  }  
 

NO.3   作者: sunnystar365

在浏览器中显示  
  string   strFile="F:\\a.doc";  
  Response.Clear();  
  Response.ClearHeaders();  
  Response.Charset   =   "GB2312";  
  Response.ContentEncoding   =System.Text.Encoding.UTF8;  
  Response.ContentType   =   "application/msword";    
  Response.WriteFile(strFile);  
   
  弹出对话框让用户保存  
  string   strFile="F:\\a.doc";  
  if(!System.IO.File.Exists(strFile))  
  {  
  Response.Write("<script   language=javascript>alert(对不起,文件不存在!);</script>");  
  return;  
  }  
  Response.Clear();  
  Response.ClearHeaders();  
  Response.Charset   =   "GB2312";  
  Response.ContentEncoding   =System.Text.Encoding.UTF8;  
  Response.ContentType   =   "application/octet-stream";    
  FileInfo   fi=new   FileInfo(strFile);  
  Response.AddHeader("Content-Disposition","attachment;     filename="     +     HttpUtility.UrlEncode(fi.Name))   ;  
  Response.AddHeader("Content-Length",fi.Length.ToString());  
  byte[]   tmpbyte=new   byte[1024*8];  
  FileStream   fs=fi.OpenRead();  
  int   count;  
  while((count=fs.Read(tmpbyte,0,tmpbyte.Length))>0)  
  {  
  Response.BinaryWrite(tmpbyte);  
  Response.Flush();  
  }  
  fs.Close();  
  Response.End();  
 

NO.4   作者: sunnystar365

删除文件,先确定文件的路径  
  string   文件路径=Server.MapPath("")+"\\文件夹名\\"+文件名;//得到文件路径  
  if(System.IO.File.Exists(imagepath))//判断是否存在此文件  
  {  
  System.IO.File.Delete(imagepath);//删除  
  }


 ·求md5码破解    »显示摘要«
    摘要: cb306d69341cdcfd 加密串如上,小弟试过n个破解工具都不行,恳望各位高手支招!谢谢!!! ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE