public string SerializaTemplate(ref DBConn oConn, string cPath, string cFile) { if (string.IsNullOrEmpty(cPath)) { return(string.Empty); } try { BinaryTemplate oTemplate = new BinaryTemplate(); CmsTemplate oCmsTemplate = new CmsTemplate(ref oConn); oCmsTemplate.CodTemplate = pCodTemplate; DataTable oData = oCmsTemplate.Get(); if (oData != null) { if (oData.Rows.Count > 0) { oTemplate.CodTemplate = oData.Rows[0]["cod_template"].ToString(); oTemplate.NomTemplate = oData.Rows[0]["nom_template"].ToString(); oTemplate.TextoTemplate = oData.Rows[0]["texto_template"].ToString(); oTemplate.ArchTemplate = oData.Rows[0]["arch_template"].ToString(); oTemplate.EstTemplate = oData.Rows[0]["est_template"].ToString(); } } oData.Dispose(); if (Directory.Exists(cPath) && !string.IsNullOrEmpty(cFile)) { IFormatter oBinFormat = new BinaryFormatter(); Stream oFileStream = new FileStream(cPath + cFile, FileMode.Create, FileAccess.Write); oBinFormat.Serialize(oFileStream, oTemplate); oFileStream.Close(); oFileStream = null; oTemplate = null; } return(string.Empty); } catch (Exception Ex) { return(Ex.Source + " - " + Ex.Message + " - " + Ex.StackTrace); } }
public BinaryTemplate ClassGet() { try { if (!string.IsNullOrEmpty(pCodTemplate)) { StringBuilder Directorio = new StringBuilder(); StringBuilder Archivo = new StringBuilder(); Directorio.Append(cPath); Directorio.Append(@"\binary\"); Archivo.Append("template_"); Archivo.Append(pCodTemplate); Archivo.Append(".bin"); if (File.Exists(Directorio.ToString() + Archivo.ToString())) { IFormatter oBinFormat = new BinaryFormatter(); Stream oFileStream = new FileStream(Directorio.ToString() + Archivo.ToString(), FileMode.Open, FileAccess.Read, FileShare.Read); BinaryTemplate oTemplate = (BinaryTemplate)oBinFormat.Deserialize(oFileStream); oFileStream.Close(); return(oTemplate); } else { return(new BinaryTemplate()); } } else { return(new BinaryTemplate()); } } catch { return(new BinaryTemplate()); } }