The code below works fine for reading json files from my project folder, the challenge am having is how to rewrite the code or changes i need to make to read text files from my project folder i have tried but to no avail.
kindly help
//code to read json files
public partial class BibleInYear : PhoneApplicationPage
{
private List
public BibleInYear()
{
InitializeComponent();
devotions = new List
AddDevotions();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
DateTime dt = DateTime.Now;
int month = dt.Month;
int year = dt.Year;
int index;
if (DateTime.IsLeapYear(year) || (month <= 2))
{
index = dt.DayOfYear - 1; // list is indexed from 0
}
else
{
index = dt.DayOfYear; // add a day
}
textblock.Text = devotions[index].ToString(); // or some other property
}
private void AddDevotions()
{
for (int i = 1; i <= 366; i++)
{
string filePath = "BibleInYear/Bible" + i.ToString() + ".json";
BibleData d = ReadJsonFile(filePath);
devotions.Add(d);
}
}
public BibleData ReadJsonFile(string JsonfilePath)
{
BibleData[] d = null;
using (StreamReader r = new StreamReader(JsonfilePath))
{
string json = r.ReadToEnd();
d = JsonConvert.DeserializeObject
}
return d[0];
}
Thank you in advance and reply soon
Joginder BangerPosted Feb 2, 2015, 2:51 PM
Jhon,
SteamReader can't the read the DLL type of file.
You can disassemble .NET Assembly (forget DLLs and EXEs — for .NET this is practically the same; well, EXE has an entry point, usually
Mainand DLL may or may not have one; that's it; EXE can be referenced as a library exactly as DLL, there are cases when it's even practical to do so).See MSIL disassembler (Ildasm.exe), http://msdn.microsoft.com/en-us/library/f7dy01k1%28v=VS.100%29.aspx
When you disassemble the assembly in IL code, you can modify it and assemble again using MSIL assembler (Ilasm.exe), see http://msdn.microsoft.com/en-us/library/496e4ekx%28v=VS.100%29.aspx
Reflector is a powerful tool, but you can have another tool free of charge: Open Source ILSpy, http://wiki.sharpdevelop.net/ilspy.ashx
It's not too difficult to "reflect" DLL using
System.Reflection, but to disassemble if in full… much, much harder.reference by -SA
JOHN JOHNNNYPosted Feb 2, 2015, 10:09 AM
When i rewrite my code i got this error "An exception of type 'System.NullReferenceException' occurred in DevotionText.DLL but was not handled in user code"
The code below
// xaml.cs
public partial class MainPage : PhoneApplicationPage
{
List
// Constructor
public MainPage()
{
InitializeComponent();
AddDevotions();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
DateTime dt = DateTime.Now;
int month = dt.Month;
int year = dt.Year;
int index;
if (DateTime.IsLeapYear(year) || (month <= 2))
{
index = dt.DayOfYear - 1; // list is indexed from 0
}
else
{
index = dt.DayOfYear; // add a day
}
textblock.Text = devotions[index].ToString(); // or some other property
}
private void AddDevotions()
{
for (int i = 1; i <= 366; i++)
{
string filePath = "Devotions/Devotion1" + i.ToString() + ".txt";
devotions.Add(d);
}
}
public string ReadTextFile(string textFilePath)
{
string text = null;
using (StreamReader r = new StreamReader(textFilePath))
{
text = r.ReadToEnd();
}
return text;
}
public string d { get; set; }
Kindly help
VulpesPosted Jan 28, 2015, 11:02 AM