tks

博客园 首页 联系 订阅 管理

首先,在页面上放一个html的input(File)控件将其命名为myFile,然后将它作为服务器断控件运行。
再放一个Button,在Button点击事件中添加以下代码:


if (this.myFile.PostedFile != null)
                
{
                    
string photoName1 = myFile.PostedFile.FileName; //获取初始文件名   
                    int i = photoName1.LastIndexOf("."); //取得文件名中最后一个"."的索引   
                    string newext = photoName1.Substring(i); //获取文件扩展名   
                    if (!FileEXT(newext))
                    
{
                        Response.Write(
"文件格式不正确!");
                        Response.End();
                    }

                    DateTime now 
= DateTime.Now; //获取系统时间   
                    photoName2 = now.ToString("yyyyMMddhhmmss"+ newext; //重新为文件命名,获取时间的年月日时分秒部分   
                    myFile.PostedFile.SaveAs(Server.MapPath("Upload/" + photoName2));
                    
// 保存文件到路径,用Server.MapPath()取当前文件的绝对目录  
                }



 

posted on 2007-04-03 14:31  特困生  阅读(315)  评论(0)    收藏  举报