Articles

Affichage des articles du mai, 2017

How to display Base64 images in HTML with c#

If you need convert image to Data  URL (embedding Image) here the code: Encode to Base64 format public static string GetDataURL ( string imgFile ) { return "<img src=\"data:image/" + Path . GetExtension ( imgFile ). Replace ( "." , "" ) + ";base64," + Convert . ToBase64String ( File . ReadAllBytes ( imgFile )) + "\" />" ; }

Properly Export Html to PDF using iTextsharp c#

iText is a PDF library that allows you to CREATE, ADAPT, INSPECT and MAINTAIN documents in the Portable Document Format (PDF). Export  Html to PDF using iTextsharp Important Note: Make sure, yea, very important make sure that your HTML is well structured and all tags are closed. If not you'll get an error. Usings using System.IO; using iTextSharp.text; using iTextSharp.text.html.simpleparser; using iTextSharp.text.pdf; Create a method called  GetPDF to create PDF stream in memory public static byte[] GetPDF(string pHTML)         {             byte[] bPDF = null;             MemoryStream ms = new MemoryStream();             TextReader txtReader = new StringReader(pHTML);             // 1: create object of a itextsharp document class             Document doc = new Docume...

Programmatically Modify ConnectioString from Properties.Settings.Default c#

Modifying ConnectioString from App Settings Programmatically on c# if(Properties.Settings.Default.appConnectionString3 != ConfigurationManager.ConnectionStrings["cn"].ConnectionString)             {                 Properties.Settings.Default["appConnectionString3"] = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;                 Properties.Settings.Default.Save();             } You can edit 'cn' from AppConfig <add name="cn" connectionString="Data Source=(localDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\app.mdf;Integrated Security=True"             providerName="System.Data.SqlClient" />      </connectionStrings>