Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8332999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:52:47+00:00 2026-06-09T02:52:47+00:00

I have a C# Visual Studio 2008 Form which needs to read the contents

  • 0

I have a C# Visual Studio 2008 Form which needs to read the contents of the relative file ‘character/attacks.txt’ File.Exists() returns false when I run it, even though I’m positive my directories are sorted. Code:

            try
            {
                System.IO.StreamReader file = new System.IO.StreamReader("character/attacks.txt");
                int counter = 0;
                int numberOfLines = 0;
                string line;
                while ((line = file.ReadLine()) != null) { numberOfLines++; }
                string[] attacks = new string[numberOfLines];
                while ((line = file.ReadLine()) != null) { attacks[counter] = line; counter++; }
                file.Close();
                print(attacks.ToString());
            }
            catch (Exception ex) 
            {
                print("ERROR"); print("Did you edit any files?"); print(ex.ToString()); 
            }

Exception Error:

System.IO.FileNotFoundException: Could not find file 'D:\Users\Andrey\Desktop\Turn\character\attacks.txt'.
File name: 'D:\Users\Andrey\Desktop\Turn\character\attacks.txt'
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
   at System.IO.StreamReader..ctor(String path)
   at TurnByTurn.Form1.button1_Click(Object sender, EventArgs e) in D:\Users\Andrey\Desktop\C#\TurnByTurn\TurnByTurn\Form1.cs:line 52

I’m porting my code from Python and never had any troubles with this. Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:52:49+00:00Added an answer on June 9, 2026 at 2:52 am

    That’s very strange. The computer seems firmly convinced that there is no attacks.txt file in the D:\Users\Andrey\Desktop\Turn\character\ directory, but you say that it definitely exists. One of you must be wrong, and I’ve learned over the years that computers are right more often than I am.

    Are you sure that your file actually has a .txt extension, not a .txt.somethingelse extension? If you have the display of file extensions turned off in the Windows shell, you might be missing this extra file extension. The computer isn’t missing it internally, though, and it’s seeing that as a totally different file than the one you requested. That’s the same problem this guy had.

    To re-configure Windows Explorer:

    1. Open the Control Panel folder.
    2. Click on “Folder Options”.
    3. Switch to the “View” tab.
    4. Find the “Show hidden files, folders, and drives” radio button in the list of items in the “Advanced settings” list box, and make sure that it is selected.
    5. Click OK.

    The other answers to this question do make some good suggestions. Among them:

    1. Make sure that if you use backslashes (which is the standard Windows path separator character) in your string literals, you “escape” them using a second backslash. The reason this is required is that the backslash is interpreted as an escape character by the C# compiler, which allows you to type things like \t to insert a tab. If you want to insert a regular backslash, you have to escape the escape—\\. That’s the reason you were getting an error when you tried to use a single backslash.

    2. Instead of escaping the backslash character, you can tell the C# compiler to interpret your string literal exactly as it is typed, including spaces. These are called verbatim string literals. You do this by prefixing the string with the @ character. For example: @"C:\MyDirectory\MyFile.txt"

    3. The reason why the forward slash character that you’re using now works is strictly for backwards-compatibility reasons. It isn’t the cause of the error (as you can see from the exception message, which includes the path being searched), but it’s probably still not a good idea to use forward slashes in paths. As I mentioned above, the backslash is the standard path delimiter in Windows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

JI have written a .NET C# Windows Form app in Visual Studio 2008 that
I'm using Visual Studio 2008 Professional in C++ with Windows Form, I have a
c# .Net 3.5 visual studio 2008, windows xp I have a main form in
I have a Windows Form Application in Visual Studio 2008 - PictureBox.Refesh() method causes
I have written a Visual Studio 2008 addin that adds controls to a Form.
I am using Visual Studio 2008. I have created a visual basic form that
I have a visual c++ windows form application (empty) made on visual studio 2008
I have Visual Studio 2008 and i installed and removed StrataFrame Framework. This framework
I have Visual Studio 2008 and the Windows SDK for Windows Server 2008 and
I have visual studio 2008. I have a written a small C program. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.