Beispiel #1
0
        protected void Button3_Click(object sender, EventArgs e)
        {
            string pSavePath = Server.MapPath("~/XLS/");

            if (!FileUpload1.HasFile)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "<script>alert('请选择要上传的文件! ')</script>", false);
                return;
            }
            string pFileName = FileUpload1.FileName;

            pSavePath += pFileName;
            FileUpload1.SaveAs(pSavePath);
            FileUpload1.Dispose();
            int i = pFileName.Length - 4;

            if (pFileName.Substring(i) == ".zip")
            {
                CompresssFiles.UnZip(pSavePath, Server.MapPath("~/XLS/"));
            }
            ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "<script>alert('上传成功! 文件名为:" + FileUpload1.FileName + "  文件类型为:" + FileUpload1.PostedFile.ContentType + "  文件大小为:" + FileUpload1.PostedFile.ContentLength + "')</script>", false);
        }
Beispiel #2
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button3_Click(object sender, EventArgs e)
        {
            string pSavePath = Server.MapPath("~/XLS/");

            if (!FileUpload1.HasFile)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "<script>alert('请选择要上传的文件! ')</script>", false);
                return;
            }
            string pFileName = FileUpload1.FileName;

            Session["mingcheng"] = pFileName.ToString();
            pSavePath           += pFileName;
            FileUpload1.SaveAs(pSavePath);
            FileUpload1.Dispose();
            int i = pFileName.Length - 4;

            if (pFileName.Substring(i) == ".zip")
            {
                CompresssFiles.UnZip(pSavePath, Server.MapPath("~/XLS/"));
            }
            //Session.Clear();

            string a = Session["mingcheng"].ToString();

            ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "<script>alert('上传成功! 文件名为:" + FileUpload1.FileName + "  文件类型为:" + FileUpload1.PostedFile.ContentType + "  文件大小为:" + FileUpload1.PostedFile.ContentLength + "')</script>", false);


            //    string name = GetFiles.FileName;//获取已上传文件的名字
            //string size = GetFiles.PostedFile.ContentLength.ToString();//获取已上传文件的大小
            //string type = GetFiles.PostedFile.ContentType;//获取已上传文件的MIME
            //string postfix = name.Substring(name.LastIndexOf(".") + 1);//获取已上传文件的后缀
            //string ipath = Server.MapPath("upimg") +"\\"+ name;//获取文件的实际路径
            //string fpath = Server.MapPath("upfile") + "\\" + name;
            //string dpath = "upimg\\" + name;//判断写入数据库的虚拟路径

            //ShowPic.Visible = true;//激活
            //ShowText.Visible = true;//激活

            ////判断文件格式
            //if (name == "") {
            //  Response.Write("<script>alert('上传文件不能为空')</script>");
            //}

            //else{

            //    if (postfix == "jpg" || postfix == "gif" || postfix == "bmp" || postfix == "png")
            //    {
            //        GetFiles.SaveAs(ipath);
            //        ShowPic.ImageUrl = dpath;
            //        ShowText.Text = "你上传的图片名称是:" + name + "<br>" + "文件大小:" + size + "KB" + "<br>" + "文件类型:" + type + "<br>" + "存放的实际路径为:" + ipath;

            //    }

            //    else
            //    {
            //        ShowPic.Visible = false;//隐藏图片
            //        GetFiles.SaveAs(fpath);//由于不是图片文件,因此转存在upfile这个文件夹
            //        ShowText.Text = "你上传的文件名称是:" + name + "<br>" + "文件大小:" + size + "KB" + "<br>" + "文件类型:" + type + "<br>" + "存放的实际路径为:" + fpath;

            //    }
        }