Generate qr code c# .net (for url for example. SVG)

Qr code are very famouse nowadays so I will teach you how to generate qr code using c# and net core. I will do an example how to encode a url.

It is very simple. Of course it is simple because somebody works hard and developed a library for us.

This library is Qr coder. It is defined like “A pure C# Open Source QR Code implementation“. You can see the full documentation and source code in github.

I am using net core 7 at the moment I write this article.

If you want to know more details about Qr code and how to it works, you can read a very good definition in wikipedia.

private static void Main(string[] args){
        Console.WriteLine("QR Codes");

        Url generator = new Url("");
        string payload = generator.ToString();

        QRCodeGenerator qrGenerator = new QRCodeGenerator();
        QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q);
        SvgQRCode qrCode = new SvgQRCode(qrCodeData);
        string qrCodeAsSvg = qrCode.GetGraphic(20);

        string file = @"c:/Home/Blog/example.svg";
        byte[] data = Encoding.ASCII.GetBytes(qrCodeAsSvg);

        System.IO.File.WriteAllBytes(file, data);

How to write csv file in c#

To create a csv file we will use “StringBuilder” and “WriteAllText” functions. It use these functions we need to add two namespaces.

  • System.Text (StringBuilder)
  • System.IO (WriteAllText)

This is a very simple way to write a CSV (Comma separated value) file. You can use this file type to export and import data between applications.

I recommend you use this format in your export options when you are developing something.

private static void Csv(List<Element> elements)
	var csv = new StringBuilder();

	string head = "Field1,Field2,Field3";

	foreach (var element in elements)
		string line = element.field1 + ";" + element.field2 + ";" + element.field3;

	File.WriteAllText("data.csv", csv.ToString());

More information about CSV file: