我必须将图像存储在数据库中............. [英] i have to store the image in DB .............

查看:36
本文介绍了我必须将图像存储在数据库中.............的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在插入图像时将其存储在DB中但在文件夹中查看
但是我只能从数据库查看我该怎么办?



这是我的代码....

when am inserting the image it is storing in DB but Viewing in folder
but i have to view from DB only what can i do?



this is my code ....

protected void Page_Load(object sender, EventArgs e)
        {
            selectnode();
            //SelectedNode = TreeView1.SelectedNode.Text;
            //TreeView1.Nodes node = TreeView1.FindNode("NMBM").Text;
            //TreeView1.SelectedNode.Text = TreeView1.FindNode("NMBM").Text;
            //TreeView1.FindNode("NMBM");
            clsUser LogedinUser = new clsUser();
            List<clspageobj> ChkList = new List<clspageobj>(); 
              ChkList=  LogedinUser.UserRolesObj(Session["UserPkid"].ToString(), Session["UserRolePkid"].ToString(), Session["UserLocationPkid"].ToString());
              var b = from ch in ChkList
                      where ch.obj_name == "wpaLocationDetails.aspx"
                      select ch.obj_status;

              bool testFrmval = (bool)b.Single();

              var SaveBtn = from ch in ChkList
                            where ch.obj_name == "btnMulSave"
                      select ch.obj_status;

              bool testSaveBtntval = (bool)SaveBtn.Single();
              if (!(bool)SaveBtn.Single())
              {
                  btnMulSave.Enabled = false;
              }
            if (IsPostBack)
            {
 
            }

            if (!IsPostBack)
            {
                Addnew();
                fill_Tree2();
                addparenttolist();
                TreeView1.ExpandAll();
                pnlright.Enabled = false;
                rightpanelbtn(false);
                leftpanelbtn(true);
                msgmulliteral.Text = "";
                clsUser MyUser = new clsUser();
                MyUser.BrowseUser(ddlmanager);
            }
            //retriveolddata(SelectedNode);
 
            setPageProperties("wpaLocationsDetails");

        }

        public bool checkFileExtension(string fname) 
        {

            if (fname.IndexOf(".") == -1)
                return false;

        string[] validExtensions = new string[5];

            

        string ext = fname.Substring(fname.LastIndexOf('.') + 1).ToLower();
        //Add valid extentions in this array
        validExtensions[0] = "jpg";
        //validExtensions[1] = 'pdf';
        for (int i = 0; i < validExtensions.Length; i++)
        {
            if (ext == validExtensions[0].ToString())
                return true;
        }

        return false;
        }


        IMA.DataClasses1DataContext forselectdb = new IMA.DataClasses1DataContext();
        private void Addnew()
        {
            //For getting the LocationID

            string test = string.Empty;
            var nodes =
                from nd in forselectdb.tbllocations
                 orderby nd.locid descending
                 select new { nd.locid, nd.locname, nd.locparentid, nd.locshortdesc };

            foreach (var lo in nodes.Take(1))
            {
                test = lo.locid.ToString();
            }

            string a = "";
            int tempid = Convert.ToInt32(test.Remove(0, 2)) + 1;
            if (tempid < 10)
            {
                a = "AA000" + tempid.ToString();
            }
            else if (tempid < 100)
            {
                a = "AA00" + tempid.ToString();
            }

            else if (tempid < 1000)
            {
                a = "AA0" + tempid.ToString();
            }

            else if (tempid < 10000)
            {
                a = "AA" + tempid.ToString();
            }

            txtMunicipalID.Text = a.ToString();
            txtMunicipalID.DataBind();
        }

        public clsLocation mylocation = new clsLocation();
        protected void btnMulSave_Click(object sender, ImageClickEventArgs e)
        {
            if (txtMulName.Text == "")
            {
                string str1 = "Name field cannot be left blank!!!";
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + str1 + "');", true);
            }
            else
            {
                if (txtMulName.Text == ddlparent.Text)
                {
                    msgmulliteral.Text = "Municipal Name and its Parent Node cannot be same.";
                }

                else
                {

                    if (fileup.HasFile)
                    {
                        file = fileup.FileName;
                        bool ans = checkFileExtension(file);
                        if (ans)
                        {


                            try
                            {

                                fileadd = (Server.MapPath("Image\\") + txtMulShortName.Text + "." + file.Substring(file.LastIndexOf(".") + 1).ToString());
                                fileup.SaveAs(fileadd);
                            }
                            catch (Exception ex) { }
                            locLogo.ImageUrl = "~/Image/" + txtMulName.Text + "." + file.Substring(file.LastIndexOf(".") + 1).ToString();
                        }
                        else
                        {
                            msgmulliteral.Text = "Invalid file type of Logo, select only JPG files";
                        }</clspageobj></clspageobj>

推荐答案

要将图像存储在DB中,请参考本文

在SQL Server中存储或保存图像 [ ^ ]


To store image in DB refer this article

Store or Save images in SQL Server[^]


fileadd = (Server.MapPath("Image\\") + txtMulShortName.Text + "." + file.Substring(file.LastIndexOf(".") + 1).ToString());
fileup.SaveAs(fileadd);



这是用于在不希望的文件夹注释中创建图像的代码



this is code for creating the image in folder comment if u dont want it




如果可以的话,请参阅我的文章.

从数据库到Gridview的显示/存储和检索图像数据

如果可以帮助的话,请不要忘记投票...

问候
Hi,

See my Article if could help...

Display/Store and Retrieve Image Data from Database to Gridview

Please do not forget to vote if could help...

Regards,


这篇关于我必须将图像存储在数据库中.............的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆