说明:
WEB 页面上有一FileUpload控件,当用户点浏览的时候,下面只文件类型只显示一行(视频文件:flv)
主要做法:去掉原来的默认三种类型。要怎么做?[所有文件,图片,HTML],添加自己想要的过滤条件。

解决方案 »

  1.   

    Boolean fileOK = false;
            String path = Server.MapPath("~/admin/UploadImg/");
            String fileExtension = "";
            if (this.Ful_Img.HasFile)
            {
                fileExtension = System.IO.Path.GetExtension(this.Ful_Img.FileName).ToLower();
                String[] allowedExtensions = { ".bmp", ".gif", ".png", ".jpeg", ".jpg" };
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (fileExtension == allowedExtensions[i])
                    {
                        fileOK = true;
                    }
                }
            }
            if (fileOK)
            {
                try
                {
                    String FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + fileExtension;
                    this.Ful_Img.PostedFile.SaveAs(path
                        + FileName);
                    this.Txt_Imgname.Text = this.Txt_Imgname.Text+","+FileName;
                    this.Lbl_Img.Text = this.Lbl_Img.Text+"第"+(this.Txt_Imgname.Text.Split(',').Length-1).ToString ()+"张图片成功 ";
                    this.Ima_Pic.ImageUrl = "~/admin/UploadImg/" + FileName;
                    this.Lbl_ImgOk.Visible = true;
                }
                catch
                {
                    this.err_show.Visible = true;
                }
      

  2.   

      <INPUT id="File1"  type="file"  name="File1" runat="server" Class="inputText" onfocus="javascript:ShowImage(this.value,document.getElementById('Image1'))">
     <asp:RegularExpressionValidator ID="FileValidator" runat="server" ControlToValidate="File1" Display="dynamic" ValidationExpression=".*([\.jpg]|[\.jpeg]|[\.jpe]|[\.gif]|[\.png]|[\.JPEG]|[\.JPG]|[\.GIF]|[\.bmp]|[\.BMP])$" ErrorMessage="jpg,jpeg,jpe,gif,png,JPEG,JPG,GIF,bmp,BMP"></asp:RegularExpressionValidator>  HttpPostedFile PostedFile = Files[i];
                    if (PostedFile.ContentLength > 0)
                    {
                        string FileName = PostedFile.FileName;
                        string AttachExt = FileName.Substring(FileName.LastIndexOf(".") + 1);                    string[] NoExPrentFile = new string[] { "exe", "asp", "aspx", "js", "php" };
                        bool IsUp = true;
                        for (int j = 0; j < NoExPrentFile.Length; j++)
                        {
                            if (AttachExt.Equals(NoExPrentFile[j]))
                            {
                                IsUp = false;
                            }
                        }
               }