Asp.net Can't save image from browser to local machine -


me have projects web use codefile on me browser photos local save path file images on database successful. on me developers project there in host can not insert path file images database of me. although project on local machine works my. can me. thank here chunk codes of me:

html code:

<%@ page title="" language="c#" masterpagefile="~/ad/admin.master" autoeventwireup="true" codefile="editproduct.aspx.cs" inherits="editproduct" %>  <asp:image id="image1" runat="server" height="91px" width="96px" /> <asp:fileupload id="fileupload1" runat="server" /></td> 

code c#:

using system; using system.data; using system.configuration; using system.collections; using system.web; using system.web.security; using system.web.ui; using system.web.ui.webcontrols; using system.web.ui.webcontrols.webparts; using system.web.ui.htmlcontrols; using bal; using dal;      protected void insert()         {             product product = new product();             //gan du lieu vao doi tuong              product.pro_keyword = txtkeyword.value + " " + txtpro_name.value;             product.pro_isdiscount = chkkhuyenmai.checked;             product.pro_price = int.parse(txtprice.value);             product.pro_name = txtpro_name.value;             product.pro_warranty = txtwarranty.text;             product.pro_condition = txtcondition.text;             product.title = txttitle.text;             product.keyword = txtgoogle_keyword.text;             product.description = txtdescription.text;              product.pro_position = 0;             product.pro_pricediscount = double.parse(txtpricediscount.value);             product.pro_iscomment = true;             product.pro_content = htmleditor2.text;             //product.pro_intro = htmleditor1.text;             product.pro_intro = txtcode_product.text;             product.cate_id = int.parse(ddlcategory.selectedvalue);              string _sfolder = request.physicalapplicationpath.replace(@"\", "/") + "/images_upload/product/";             product.pro_createdate = datetime.now;              if (string.isnullorempty(fileupload1.filename) == false)             {                 product.pro_image = extendfunctional.uploadpicture(_sfolder, fileupload1.postedfile);                 image1.imageurl = "../images_upload/product/" + product.pro_image;             }             //if (string.isnullorempty(fileupload2.filename) == false)             //{             //    product.pro_bigimage = extendfunctional.uploadpicture(_sfolder, fileupload1.postedfile);             //    image2.imageurl = "/images/products/" + product.pro_bigimage;             //}             product.pro_pricediscount = 0;             product.pro_status = true;             //them moi             product_bal.insert_product(product);             response.write("<script>alert('Đã thêm mới thành công!') ; window.location.href='manageproduct.aspx'</script>");              //messagebox.show("Đã thêm mới thành công.");          } 

class extendfunctional:

using system; using system.data; using system.configuration; using system.web; using system.web.security; using system.web.ui; using system.web.ui.webcontrols; using system.web.ui.webcontrols.webparts; using system.web.ui.htmlcontrols;       public class extendfunctional     {         public static bool isnumberic(string str)         {             try             {                 if (string.isnullorempty(str)) return false;                 int = convert.toint32(str);                 return true;             }             catch { return false; }         }           public static void deleteimageinfolder(string path)         {             if (system.io.file.exists(path))             {                 system.io.file.delete(path);             }         }         public static bool isimagefile(string filename)         {             try             {                 string[] extend = new string[] { ".gif", ".bmp", ".jpg", ".jpeg", ".png" };                  string ex = filename.substring(filename.length - 4).tolower();                 foreach (string s in extend)                     if (s == ex) return true;                 return false;             }             catch { return false; }         }         public static string uploadpicture(string _sfolder, httppostedfile _file)         {             string _sresult = "";             if (!system.io.directory.exists(_sfolder))                 system.io.directory.createdirectory(_sfolder);              string _sfilename = system.io.path.getfilename(_file.filename);             try             {                 _file.saveas(_sfolder + "/" + _sfilename);                 _sresult = _sfilename;             }             catch (exception)             {              }             return _sresult;         }     } 


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -