0

I'm storing some data in a txt file and using that as a data source to populate my combobox.

This is my Mainpage.cs code:

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
        this.LoadComboBox();
    }

    public async void LoadComboBox()
    {

        await Task.Run(() =>
        {
            Task.Yield();
            try
            {
                string[] lineOfContents = File.ReadAllLines(@"C:\path\to\myData.txt");
                foreach (var line in lineOfContents)
                {
                    comboBox1.Items.Add(line);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.StackTrace);
            }

        });
    }
}

Error:

Access to the path "..." is denied.

I've already modified the file properties to give full permission to Network Service if that helps.

Appreciate your help.

90abyss
  • 7,037
  • 19
  • 63
  • 94
  • That error typically means exactly what it says. Try giving everyone full control. – Neo Oct 13 '16 at 17:24
  • I already have given full control to everyone (Authenticated Users, Administrators, Network Service, Users).. to all the options I could find in the security tab of the text file I've given permissions – 90abyss Oct 13 '16 at 17:32
  • Just to be 100% clear, this is on your workstation, correct? If you copy your path being used by the application into a fresh explorer window, minus the file, you find the file, correct? – Neo Oct 13 '16 at 17:33
  • Yes it is on my local machine. – 90abyss Oct 13 '16 at 17:37
  • Be curious to know the outcome – Neo Oct 13 '16 at 17:49
  • 1
    An UWP app is sandboxed, you normally don't have access to the C:\ or any other drive. Include the file with your package (eg in the Assets folder) and read it with the ms-apx protocol. – H H Oct 13 '16 at 18:04
  • For a full answer: what is the role of myData.txt, how often does it change, ... – H H Oct 13 '16 at 18:05

0 Answers0