C# Base64 String to PNG Image

Here’s how you can save a base64 encoded string to image file in C#. public void SaveImageFile(string filename, string base64Image) { string destinationImgPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + Constants.UserImagesPath+"\\"+filename+".png"; try { Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + Constants.UserImagesPath); } catch (IOException iox) { Console.WriteLine(iox.Message+" "+iox.Data); } var bytes = Convert.FromBase64String(base64Image); using (var imageFile = new FileStream(destinationImgPath, FileMode.Create)) { imageFile.Write(bytes, 0, bytes.Length); […]

Read More

Call C-Sharp from javaScript using CefSharp in WPF app

Here’s how you can invoke a C# function from javaScript while using CefSharp in a WPF app. Step 1: Create a Class with the Method to be Invoked Create a CallbackObjectForJs class that contains a showMessage function which would be invoked from javascript. public class CallbackObjectForJs{ public void showMessage(string msg){//Read Note MessageBox.Show(msg); } } Step […]

Read More

What Is a Universal Windows Platform (UWP) App?

The concept of a common application architecture was first introduced in Windows 8 as the Windows Runtime. Windows Runtime (WinRT) was an evolution of the Windows app model, intended to be a common application architecture. When Windows Phone 8.1 became available, the Windows Runtime was aligned between Windows Phone 8.1 and Windows. This enabled developers […]

Read More

How to Calculate the Difference in Months Between two Dates C#

This code snippet lets you calculate the difference in months between two dates. If all you want is simply a difference in the months -completely disregarding the date values- then you can use this: public static int MonthDifference(this DateTime lValue, DateTime rValue) { return (lValue.Month – rValue.Month) + 12 * (lValue.Year – rValue.Year); } Note […]

Read More