Skip to content

Instantly share code, notes, and snippets.

@UdaraAlwis
Last active August 20, 2019 11:46
Show Gist options
  • Save UdaraAlwis/82d3e0cbb47eb71e55eafc8a42efd68c to your computer and use it in GitHub Desktop.
Save UdaraAlwis/82d3e0cbb47eb71e55eafc8a42efd68c to your computer and use it in GitHub Desktop.
Read the Json File content added as EmbeddedResources in your VS project
using System;
using System.IO;
using System.Reflection;
namespace WhateverYourNamespace
{
public static class JsonFileHelper
{
public static string GetJsonFileString()
{
// get current assembly
var assembly = Assembly.GetExecutingAssembly();
// get the embedded file path
var resourceName = "WhateverYourNamespace.Resources.myjsondata.json";
string jsonString = string.Empty;
// load the file data stream
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
{
// read the json string
jsonString = reader.ReadToEnd();
}
// jsonString : your json content string is ready
return jsonString;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment