private void Button1_Click(object sender, System.EventArgs e)

              {

                     if (File1.PostedFile != null)

                     {

                            //上传文件的文件名(含完整路径)

                            string fileName = File1.PostedFile.FileName ;

                            //上传文件的大小(byte)

                            int fileLength = File1.PostedFile.ContentLength ; km

                            string sMsg = null;

                            //判断文件大小是否超过200K

                            if (fileLength > (200*1024))

                            {

                                   sMsg = fileName + "文件超过200K字节!";

                            }

                            else

                            {

                                   //取文件名

                                   fileName = fileName.Substring (fileName.LastIndexOf (@"\"));

                                   //使用SaveAs方法,将文件保存在项目路径\upload目录下

                                   File1.PostedFile.SaveAs (HttpRuntime.AppDomainAppPath  + @"upload\" + fileName);

                                   sMsg = "成功上传文件:" + fileName + "文件大小:" + fileLength + "字节" + "文件类型:" + File1.PostedFile.ContentType  ;

                            }

                            //使用JavaScript显示操作结果信息

                            Response.Write ("<script language='JavaScript'>window.alert('" + sMsg + "');</script>");

                     }

              }

posted on 2013-12-30 18:16  易尔购  阅读(3274)  评论(0编辑  收藏  举报