• 如何实现文件的上传


         在asp.net中有一个HtmlInputFile HTML控件,该控件可以用来在客户端选择要上传的文件,并把文件上传   到服务器端.  

      方法一 

         string sFileName = Path.GetFileName(this.File1.PostedFile.FileName);//获取文件名
            string sFilePath = Server.MapPath("./Image/" + sFileName);//MapPath方法,把客户端的文件上传到服务器上指定的文件夹下.
            this.File1.PostedFile.SaveAs(sFilePath);

     方法二

    上传文件的同时获取文件的后缀名

                string TrueName = "";
                string RandomName = "";
                int ii;
                #region 上传图片
                string RandomString = Convert.ToString(Guid.NewGuid());
                TrueName = Path.GetFileName(ImageFile.PostedFile.FileName);
                ii = TrueName.LastIndexOf(".");
                if (ii != -1)
                {
                    string ExtendName = TrueName.Substring(ii);
                    RandomName = RandomString + ExtendName;
                    string filepath = Server.MapPath("~/Images/Photo/" + RandomName);
                    if (ExtendName != ".jpg" && ExtendName != ".gif" && ExtendName != ".bmp" &&  ExtendName != ".JPG" && ExtendName != ".GIF" && ExtendName != ".BMP")
                    {
                        Response.Write("<script language=\"javascript\">alert('只能上传jpg,gif,bmp格式的图片!');</script>");
                        return;
                    }
                    if (ImageFile.PostedFile.ContentLength > 202800)
                    {
                        Response.Write("<script language=\"javascript\">alert('上传图片不能超过200k!');</script>");
                        return;
                    }
                    else
                    {
                        ImageFile.PostedFile.SaveAs(filepath);
                    }
                }
                #endregion

  • 相关阅读:
    linux 终端光标消失问题
    linux系统中条件测试语句
    linux shell if语句
    linux shell for循环
    linux 系统中read命令
    linux中while循环语句
    linux shell脚本中流程控制语句 if 、for、while、case
    pc端WINCE的安装包
    WinCE程序的几种开发方法
    Wince 下开发技巧(一)查看内存
  • 原文地址:https://www.cnblogs.com/zhc088/p/677470.html
Copyright © 2020-2023  润新知