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 3339770
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:31:51+00:00 2026-05-18T00:31:51+00:00

The code below gives me three compiler errors. They are as follows: The type

  • 0

The code below gives me three compiler errors. They are as follows:

  1. The type or namespace name ‘TextWriter’ could not be found (are you missing a using directive or an assembly reference?)
  2. The name ‘File’ does not exist in the current context
  3. The name ‘filename’ does not exist in the current context

Can anyone provide some clarification as to why these errors are occurring, and how I can fix them?

private void button1_Click(object sender, EventArgs e)
{
   using (TextWriter writer = File.CreateText(filename.txt)) {
      writer.WriteLine("First name: {0}", textBox1.Text);
      writer.WriteLine("Last name: {0}", textBox2.Text);
      writer.WriteLine("Phone number: {0}", maskedTextBox1.Text);
      writer.WriteLine("Date of birth: {0}", textBox4.Text);
   } 
}
  • 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-05-18T00:31:51+00:00Added an answer on May 18, 2026 at 12:31 am

    For Error 1 and Error 2, make sure you are using System.IO;

    For Error 3, if the name of the file to be read is “filename.text”, make sure you place the quotes like so:

    using (TextWriter writer = File.CreateText("filename.txt"))
    

    because otherwise it is trying to find a variable filename and property txt rather than the string “filename.txt”.

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

Sidebar

Related Questions

I'm working on old code that relies heavily on the exception specifications behavior described
For some complicated reason, I want to convert any supported type T (coming from
The Story After cleaning up my Dreamhost shared server's home folder from all the
FYI I'm programming in objective-C but anyone might be able to help. I've been
I'm using boost for several C++ projects. I recently made a upgrade (1.33.1 to
First of all, my target here is to read from a URL, parse it,
I posted earlier ( OOP in C, implementation and a bug ) about my
I have two C DLLs that I need to access in the same executable.
I'm currently learning libgmp and to that end I'm writing a small program which
I am trying to call a class method dynamically depending on a condition. This

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.