上传bmp文件时,此网页无法显示错误

时间:2016-10-07 06:04:11

标签: c# asp.net

enter image description here我有一个包含4种文件类型(jpg,pdf,kmz,bmp)的下拉列表,我正在收集一些其他信息并将其绑定到网格,然后将其保存到数据库。一切都适用于前三种文件类型。但是,当我选择bmp文件类型并点击提交时,它会抛出“此网页无法显示”。它甚至没有调试点。我的意思是(提交)按钮单击事件不适用于bmp文件类型。我不知道出了什么问题。请找到以下代码。

protected void btn_add_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid)
            {

                if (FileUpload2.HasFile)
                {

                    if (FileUpload2.PostedFile.ContentType == "application/pdf" || FileUpload2.PostedFile.ContentType == "image/jpeg" || FileUpload2.PostedFile.ContentType == "image/pjpeg" || FileUpload2.PostedFile.ContentType == "application/vnd.google-earth.kmz" || FileUpload2.PostedFile.ContentType == "image/bmp" || FileUpload2.PostedFile.ContentType == "image/x-windows-bmp")
                    {
                        try
                        {

                            Byte[] app_id_doc = null;
                            HttpPostedFile File = FileUpload2.PostedFile;
                            app_id_doc = new Byte[File.ContentLength];
                            Byte[] imgByte = null;

                            string filePath = FileUpload2.PostedFile.FileName;
                            ViewState["filename"] = filePath;
                            string filename1 = Path.GetFileName(filePath);
                            string extension = Path.GetExtension(filePath);
                            ViewState["ext"] = extension;

                            HttpPostedFile File1 = FileUpload2.PostedFile;
                            imgByte = new Byte[File1.ContentLength];

                            File.InputStream.Read(imgByte, 0, File.ContentLength);
                            ViewState["imgbyte"] = imgByte;

                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
                string ddlext = ddl_doc.SelectedItem.Text.ToLower();
                string ext = ViewState["ext"].ToString().ToLower().Replace(".", "").Trim();


                if (ddlext != ext)
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Kindly upload document of selected type.')", true);
                    return;
                }
                else
                {
                    filldata();
                    btn_add.Enabled = false;
                    lbl.Text = ViewState["filename"].ToString().Trim();
                    btn_save.Visible = true;
                }
            }
        }
        catch (Exception ex)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", ex.Message, true);
        }
    }

    public void filldata()
    {
        List<int> arr = new List<int>();
        List<int> arr1 = new List<int>();
        dt = new DataTable();
        dt = (DataTable)ViewState["data"];
        if (dt == null || dt.Rows.Count == 0)
        {
            dt = new DataTable();
            dt.Columns.Add(new DataColumn("cat_id", typeof(int)));
            dt.Columns.Add(new DataColumn("doc_id", typeof(int)));
            dt.Columns.Add(new DataColumn("Category", typeof(string)));
            dt.Columns.Add(new DataColumn("Doc_Name", typeof(string)));
            dt.Columns.Add(new DataColumn("Doc_Tags", typeof(string)));
            dt.Columns.Add(new DataColumn("Doc_Desc", typeof(string)));
            arr = ddl_cat.GetSelectedIndices().ToList();
            ViewState["list"] = arr;
            for (int j = 0; j < arr.Count; j++)
            {
                dt.Rows.Add(ddl_cat.Items[arr[j]].Value.Trim(), ddl_doc.SelectedValue.Trim(), ddl_cat.Items[arr[j]].Text.Trim(), txt_trn_name.Text.Trim(), txt_trn_tags.Text.Trim(), txt_trn_desc.Text.Trim());
            }
        }
        else
        {
            arr = (List<int>)ViewState["list"];
            arr1 = ddl_cat.GetSelectedIndices().ToList();
            for (int x = 0; x < arr1.Count; x++)
            {
                arr.Add(arr1[x]);
            }
            ViewState["list"] = arr;
            for (int j = 0; j < arr1.Count; j++)
            {
                dt.Rows.Add(ddl_cat.Items[arr1[j]].Value.Trim(), ddl_doc.SelectedValue.Trim(), ddl_cat.Items[arr1[j]].Text.Trim(), txt_trn_name.Text.Trim(), txt_trn_tags.Text.Trim(), txt_trn_desc.Text.Trim());
            }
            for (int i = 0; i < arr.Count; i++)
            {
                ddl_cat.Items[arr[i]].Selected = true;
            }
        }
        GridView1.DataSource = dt;
        GridView1.DataBind();
        GridView1.Columns[0].Visible = GridView1.Columns[1].Visible = false;
        ViewState["data"] = dt;
        GridView1.Visible = true;[![enter image description here][1]][1]
    }

enter image description here

0 个答案:

没有答案