© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
8 replies
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
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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ ✅ C# program can't find folder in the very same directory
C#CC# / help
3y ago
Can't read from MemoryStream from current position
C#CC# / help
3y ago
✅ project can't find file that is in bin folder avalonia
C#CC# / help
2y ago
Single-file executable can't find dependency DLL in its folder
C#CC# / help
5mo ago