public static bool GeneratePDF(string html, int id) { using (dbDataContext db = new dbDataContext()) { OSATBL_PWF_Zadost zadost = db.OSATBL_PWF_Zadosts.Where(a => a.id == id).FirstOrDefault(); if (zadost != null && zadost.pdf == null) { PdfConverter pdfConverter = new PdfConverter(); byte[] pdf = pdfConverter.GetPdfBytesFromHtmlString(html); zadost.pdf = new System.Data.Linq.Binary(pdf); //try //{ // FileStream fs = new FileStream(@"C:\Shared\" + id.ToString() + ".pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite); // fs.Write(pdf, 0, pdf.Length); //} //catch (Exception) { } try { db.SubmitChanges(); return true; } catch (Exception) { } } return false; } }
protected void Regenerate_Click(object sender, EventArgs e) { int check = -1; using (dbDataContext db = new dbDataContext()) { foreach (OSATBL_PWF_Zadost zadost in db.OSATBL_PWF_Zadosts) { string xml = zadost.xml; xml = xml.Replace("Email", "EMail"); if (!xml.Contains("<?xml version=\"1.0\" encoding=\"utf-8\" ?>")) { xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n" + xml; } foreach (string node in xml.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)) { if (node.Contains("<Cena>")) { string nodeText = node.Trim().Replace("<Cena>", string.Empty).Replace("</Cena>", string.Empty); if (nodeText.Length > 6) { string newNodeText = nodeText.Remove(6); xml = xml.Replace(node, node.Replace(nodeText, newNodeText)); } } if (node.Contains("<Registrace>")) { check = 2; } if (check >= 0) { if (check == 0) { xml = xml.Replace(node, node.Replace("EMail", "Email")); } check--; } } zadost.xml = xml; try { db.SubmitChanges(); } catch { ErrorStatus(); return; } } } SuccessStatus(); }