Search code examples
c#windows-phone-8winrt-xaml

How to Display different html pages according to date and time of the month in a webview in windows phone 8:


I have 366 html pages in my app each html page for a day of the year that i will like to view locally in my app the code below can only view single html page but what i want is To display different html pages for each day according to date of the month in a webview i.e if the user opens the app on 2/3/2016 the app should open devotion62.html which is the 62nd day of the year This is my code below XAML

<!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <phone:WebBrowser HorizontalAlignment="Left" Margin="20,50,0,0" Name="webBrowser1" VerticalAlignment="Top" Height="500" Width="430" />
        </Grid>

XAML.CS

public partial class MainPage : PhoneApplicationPage
    {
        private List<string> htmls;

        private int CurrentIndex = 0;

        private int TotalCount = 0;
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();

            this.Loaded += MainPage_Loaded;
        }

        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            htmls = new List<string>() { "/Bible/devotion60.html", "/Bible/devotion61.html", "/Bible/devotion62.html", "/Bible/devotion63.html" };//List of string will contain all the 366 html files path
            TotalCount = htmls.Count;
            if (TotalCount != 0)

            {
                webBrowser1.Navigate(new Uri(htmls[CurrentIndex], UriKind.Relative));
            }

        }

        private void Previous_Click(object sender, EventArgs e)
        {
            if (CurrentIndex != 0)
            {
                CurrentIndex--;
            }

            webBrowser1.Navigate(new Uri(htmls[CurrentIndex], UriKind.Relative));
        }

        private void Next_Click(object sender, EventArgs e)
        {
            if (CurrentIndex != TotalCount - 1)
            {
                CurrentIndex++;
            }

            webBrowser1.Navigate(new Uri(htmls[CurrentIndex], UriKind.Relative));
        }

Solution

  • In your MainPage_Loaded method add the following code.

    CurrentIndex = DateTime.Now.DayOfYear;