如何使用实体框架在Webform中插入图像? [英] How do I insert an image in a webform using entity framework?

查看:79
本文介绍了如何使用实体框架在Webform中插入图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是逻辑。 Insert适用于所有其他字段。 BUt Imagepath取空。



This is the logic. Insert is working fine for all other fields. BUt Imagepath is taking null.

if (btn_add.Text == "Submit")
        {
           
               
                

                BracketAccessoriesEntity.BracketSuspensionType = Convert.ToString(txt_BracketSuspensionType.Text.Trim());
                BracketAccessoriesEntity.PoleTypeID = Convert.ToInt64(dd_PoleTypeID.SelectedValue.Trim());
                BracketAccessoriesEntity.AccessoryID = Convert.ToInt32(ViewState["Id"]);
                BracketAccessoriesEntity.Status = chk_Active.Checked;
                System.Collections.Hashtable ht = (System.Collections.Hashtable)Session["UserDetails"];
                Int64 UsrId = (Int64)ht["UserID"];
                BracketAccessoriesEntity.UpdatedBy = UsrId;
                BracketAccessoriesEntity.UpdatedOn = (DateTime.Now);
                string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);
                fileuploadimages.SaveAs(Server.MapPath("~/Images/Bracket Type/" + filename));
                BracketAccessoriesEntity.ImagePath = "~/Images/Bracket Type/" + filename;

                try
                {
                    string result = logic.InsertData(BracketAccessoriesEntity);
                    if (result == "SUCCESS")
                    {
                        string jScript = "<script>alert ('" + "Record Updated Successfully" + "')</script>";
                        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "starScript", jScript, false);
                        clear();
                       
                        BindGrid();
                    }





我知道我在使用Image path犯了错误。你能否建议我应该在这些方面写些什么,因为这里可能有错误。



I know I am making mistake with Image path. Can you please suggest what should I write in these lines because maybe mistake is here.

string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);
fileuploadimages.SaveAs(Server.MapPath("~/Images/Bracket Type/" + filename));
BracketAccessoriesEntity.ImagePath = "~/Images/Bracket Type/" + filename;

推荐答案

确保行

Make sure that the line
Path.GetFileName(fileuploadimages.PostedFile.FileName);



未返回NULL。


is not returning NULL.


这篇关于如何使用实体框架在Webform中插入图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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