Hi
I am developing an app that has 365 text files in my local folder, the essence of the app is to display each content of the text file according to the day of the year e.g for feb 3 2015 it will display Devotion34.txt but when i run it on the emulator is displaying May 14 which is Devotion134.txt i.e it jumps 100 days ahead of the year
This my code below kindly help
xaml.cs
public partial class MainPage : PhoneApplicationPage
{
List<String> devotions = new List<string>();
// Constructor
public MainPage()
{
InitializeComponent();
AddDevotions();
int index = DateTime.Now.DayOfYear;
textblock.Text = devotions[index];
// 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 = Path.GetFullPath("Devotions/Devotion1" + i.ToString() + ".txt");
if (File.Exists(filePath))
{
devotions.Add(ReadTextFile(filePath));
}
else
{
devotions.Add(string.Format("Devotions file '{0}' was not found.", i));
}
}
}
public string ReadTextFile(string textFilePath)
{
string text = null;
using (StreamReader r = new StreamReader(textFilePath))
{
text = r.ReadToEnd();
}
return text;
}
Reply soon and thank you in advance