c# - jpeg to byte array, while conversion logic is inside if statement -
i'm sure simple issue inexperienced developers able do, i'm starting out.
i've put if statement round logic convert jpeg byte array conversion doesn't happen unless there file selected. makes variable logobytes
invisible data parameter. colleague told me have put logic conversion method, , reference method somewhere, i'm still rather confused.
protected void btnsubmit_click(object sender, eventargs e) { div1.visible = true; if (logoprvw.value != null) { system.drawing.image img = system.drawing.image.fromfile(logoprvw.value); byte[] logobytes; using (memorystream ms = new memorystream()) { img.save(ms, system.drawing.imaging.imageformat.jpeg); logobytes = ms.toarray(); } } templatedata data = new templatedata(txtschemecode.text, txtversion.text, txtcomment.text, txttemplateid.text, logobytes); if (ddschemecode.selectedindex == 0) { lblcreated.visible = true; lblupdated.visible = false; dataclass.addnewschemecode(data); } if (ddschemecode.selectedindex == 0 && ddversion.selectedindex != 0) { lblcreated.visible = true; lblupdated.visible = false; dataclass.addnewversion(data); } if (ddschemecode.selectedindex != 0 && ddversion.selectedindex == 0) { lblupdated.visible = true; lblcreated.visible = false; dataclass.updatedata(data); }
here templatedata
class
public class templatedata { public byte[] logo { get; set; } public string templateid { get; set; } public string schemecode { get; set; } public string version { get; set; } public string comment { get; set; } public templatedata(string schemecode, string version, string comment, string templateid, byte[] logo) { schemecode = schemecode; version = version; comment = comment; templateid = templateid; logo = logo; } public templatedata(sqldatareader dr) { initialisedata(); if (dr.hasrows) { version = dr["version"].tostring(); logo = (byte[])dr["logo"]; templateid = dr["templateid"].tostring(); comment = dr["comment"].tostring(); schemecode = dr["schemecode"].tostring(); } }
if logoprvw.value
null
, don't want create data object or follow rest of code. maybe, solution simple as:
if (logoprvw.value != null) return; system.drawing.image img = system.drawing.image.fromfile(logoprvw.value); byte[] logobytes; using (memorystream ms = new memorystream()) { img.save(ms, system.drawing.imaging.imageformat.jpeg); logobytes = ms.toarray(); } templatedata data = new templatedata(txtschemecode.text, txtversion.text, txtcomment.text, txttemplateid.text, logobytes); //rest of code
Comments
Post a Comment