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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:48:56+00:00 2026-05-26T10:48:56+00:00

I have code that is supposed to take all the user data that was

  • 0

I have code that is supposed to take all the user data that was input after the program was run and put it all into a text file.

Here is the code so far:

protected void WriteFile(object sender, EventArgs e)
    {
        FileStream fs = new FileStream(@"C:\Users\4567\MyDocuments\ExporterOutput.txt", FileMode.OpenOrCreate, FileAccess.Write);
        TextBox[] tbs = { username, TextBox2, sgml, Path };
        StringBuilder sb = new StringBuilder();
        foreach (TextBox tb in tbs)
            sb.AppendLine(tb.Text);
        sb.AppendLine(DropDownList1.SelectedItem.ToString());
        sb.AppendLine(DropDownList2.SelectedItem.ToString());

        System.IO.File.WriteAllText(@"C:/Users/4567/My Documents/ExporterOutput.txt", sb.ToString());

I tried running it and the text file just shows up blank. Can anyone tell me what I am doing wrong and if there is an easier way to output all textbox information to a text file. And preferrable in a certain format.


Here is the edited code from the suggestions you gave me:

 protected void WriteFile(object sender, EventArgs e)
    {
        TextBox[] tbs = { username, TextBox2, sgml, Path };
        StringBuilder sb = new StringBuilder();
        foreach (TextBox tb in tbs)
            sb.AppendLine(tb.Text);
        sb.AppendLine(DropDownList1.SelectedItem.ToString());
        sb.AppendLine(DropDownList2.SelectedItem.ToString());

        System.IO.File.WriteAllText(@"C:\\Users\\oZ012D\\My Documents\\ExporterOutput.txt", sb.ToString());
    }
  • 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-26T10:48:56+00:00Added an answer on May 26, 2026 at 10:48 am

    Ok, Im going to take a few guesses here.

    Your last line should be

    System.IO.File.WriteAllText(@"C:\\Users\\4567\\My Documents\\ExporterOutput.txt", sb.ToString());
    

    You are using windows, so you need the “\” char and not the forward slash like you would on Linux. This is accomplished by having the double backslash (which c# recognizes as a single backslash) in your string.

    Also, try getting rid of your first line. You are creating a file stream and then not using or closing it. I think its possible that the open FS is causing issues.

    Don’t worry about creation issues, the WriteAllText() call will create the file if it doesn’t exist and will overwrite it if it does.

    Let me know if that works, the only other thing that looks potentially incorrect to me is the way you are getting text from the drop down menus.

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

Sidebar

Related Questions

I'm writing code for an Android application that is supposed to take data, package
I have a very simple bit of code that is supposed to capture the
I have code that looks like: //System.Data.IDataRecord dr try { Consolidated = Utility.NullConvert.ToBool(dr[Constants.Data.Columns.cConsolidated], false);
Suppose I have code that maintains a parent/children structure. In such a structure I
Suppose I have some code that would, in theory, compile against any version of
Suppose I have a line of code that starts like the following: Func1(Func2(Func3 Is
I have this javascript code below that uses jquery, it is suppoed to be
Suppose we have the xhr 'POST' request that returns 'redirect' status code. In that
I have code that references a web service, and I'd like the address of
I have code that looks like the following, which works fine for displaying the

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.