C#C
C#2y ago
skarab

Can't read from file in same folder

I am trying to select a random line from a txt file in the same folder, it is called "pickupDA.txt" and so I have tried to get the lines from it with File.ReadAllLines("pickupDA.txt"); but it doesnt work. i have tried with "./pickupDA.txt" and "/pickupDA.txt" and ".\pickupDA.txt", none of it works
using MauiAppInformatik.ViewModel;
using System;
using System.IO;

namespace MauiAppInformatik
{
    public partial class MainPage : ContentPage
    {
        private string PLOTD()
        {
            string[] lines = File.ReadAllLines("pickupDA.txt"); // FIX PATH 

            int seed = DateTime.Now.DayOfYear;

            Random random = new Random(seed);
            int randomIndex = random.Next(0, lines.Length);

            string selectedLine = lines[randomIndex];

            return selectedLine;
        }

        // More code here
image.png
Was this page helpful?