Read file in C # .net

I am developing an application in Windows Phone 7 in which I need to read a text file. I am writing code for this, but when I debug this code, it gives the error "exception to the method." the same code works in a C # windows form application. I do not know what the problem is. Plz suggest me for this and solve this problem. my code looks like this:

namespace fileread
{
    public partial class MainPage : PhoneApplicationPage
    {

        private string line;

        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            StreamReader sr = new StreamReader(@"D:\abc.txt");
            line = sr.ReadLine();
            MessageBox.Show(line);
        }

Error in the line: "line = sr.ReadLine ();"

+3
source share
2 answers

Are you trying to open the file on your computer in this line, from the WP7 emulator?

StreamReader sr = new StreamReader(@"D:\abc.txt");

You will definitely not be able to do this from the phone, as the applications are isolated from each other for security reasons.

, , , System.Windows.Application.GetResourceStream:

var resource = System.Windows.Application.GetResourceStream(new Uri("textfile.txt", UriKind.Relative)

. .

+6

, , WP7, . , - , .

WP7 , , , . IsolatedStorageFile.GetUserStoreForApplication() .

: .

+3

Source: https://habr.com/ru/post/1769699/


All Articles