C# 图片地址的存储和取出

版权声明:随便看,喜欢的话加我qq,一起讨论。 https://blog.csdn.net/qq_43687284/article/details/84236955
 //设置保存路径
            string name = inputfile.FileName;       //获取文件名
            string type = name.Substring(name.LastIndexOf(".") + 1);    //获取文件类型
            string ipath = Server.MapPath("Image") + "\\" + name;    //获取文件路径
            string wpath = "Image\\" + name;        //[color=red]设置文件保存相对路径(这里的路径起始就是我们存放图片的文件夹名)[/color]
            string query1 = "insert into geren(tuxiang) values('" + wpath + "')";
            if (type == "jpg" || type == "gif" || type == "bmp" || type == "png")
            {
                inputfile.SaveAs(ipath);        //服务器保存路径
                DB.fangfa(query1);
            }
//取出
 string   cmd = "select tuxiang from geren where id=12";
            SqlConnection conn = DB.lianjie();
            conn.Open();
            SqlCommand  dcmd = new SqlCommand(cmd,conn);
            SqlDataReader reader = dcmd.ExecuteReader();
            reader.Read();
            string path = reader[0].ToString();
            Image1.ImageUrl = path;
            conn.Close();

猜你喜欢

转载自blog.csdn.net/qq_43687284/article/details/84236955