0
votes

I'm making the app and it involves crating a local account using textfiles etc. At first time run, the app is meant to navigate to the page called "MainPage" but, if the file "FTR.dat" doesn't exist in this certain folder then it will navigate to "CreateAccount" page but if the file "FTR.dat" does exist in that certain folder then it wil navigate to "MainPage"

but I get this nullrefrenceexception error: Here's my code:

  Dim myIsolatedStorage As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
    If myIsolatedStorage.FileExists("PasswordManagerAccount/FTR.dat") = False Then

        NavigationService.Navigate(New Uri("/CreateAccount.xaml", UriKind.Relative))

    ElseIf myIsolatedStorage.FileExists("PasswordManagerAccount/FTR.dat") = True Then

        NavigationService.Navigate(New Uri("/MainPage.xaml", UriKind.Relative))

    End If

Thanks!

1
Let me guess: you're calling this code from the page's constructor - Kevin Gosse
Hi, Im soo sorry for the late reply! but yes, i was calling it from the MainPage if thats what you mean. So how can i execute this? - Ahmed.C

1 Answers

1
votes

You can't call this kind of code from the page constructor because the navigation service hasn't been initialized yet. Move it to the Loadedevent or OnNavigatedTo:

Protected Overrides Sub OnNavigatedTo(ByVal e As System.Windows.Navigation.NavigationEventArgs)
    Dim myIsolatedStorage As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
    If myIsolatedStorage.FileExists("PasswordManagerAccount/FTR.dat") = False Then
        NavigationService.Navigate(New Uri("/CreateAccount.xaml", UriKind.Relative))
    ElseIf myIsolatedStorage.FileExists("PasswordManagerAccount/FTR.dat") = True Then
        NavigationService.Navigate(New Uri("/MainPage.xaml", UriKind.Relative))
    End If
End Sub