|
|
|
ASP.NET中上传下载文件
作者:佚名 来源:Linux 宝库 点击: 日期:2006-11-23 |
|
--> //检查上传文件不为空 if(File1.PostedFile!=null) { string nam = File1.PostedFile.FileName ; //取得文件名(抱括路径)里最后一个"."的索引 int i= nam.LastIndexOf("."); //取得文件扩展名 string newext =nam.Substring(i); //这里我自动根据日期和文件大小不同为文件命名,确保文件名不重复 DateTime now = DateTime.Now; string newname=now.DayOfYear.ToString()+File1.PostedFile.ContentLength.ToString(); //保存文件到你所要的目录,这里是IIS根目录下的upload目录.你可以改变. //注意: 我这里用Server.MapPath()取当前文件的绝对目录.在asp.net里""必须用""代替 File1.PostedFile.SaveAs(Server.MapPath("upload"+newname+newext)); this.HyperLink1.NavigateUrl ="upload"+newname+newext; //得到这个文件的相关属性:文件名,文件类型,文件大小 //fname.Text=File1.PostedFile.FileName; //fenc.Text=File1.PostedFile.ContentType ; //fsize.Text=File1.PostedFile.ContentLength.ToString(); }
|
|
|
|
【文章评论】
【收藏本文】
【推荐好友】
【打印本文】
【论坛讨论】 |
相关文章: |
|
|
文章评论:(条) |
|
|
|
|
责任编辑:一分 声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。 |
|