Last active
August 20, 2019 11:46
-
-
Save UdaraAlwis/82d3e0cbb47eb71e55eafc8a42efd68c to your computer and use it in GitHub Desktop.
Read the Json File content added as EmbeddedResources in your VS project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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