StreamRead/Write filename issue.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Solemn
    New Member
    • Jun 2012
    • 2

    StreamRead/Write filename issue.

    in this example:

    Code:
    using (StreamWriter sw = new StreamWriter("D:\\BrugerID.txt", true))
    I want the "BrugerID" to be replaced with a variable. The variable should be a user input.

    In my perfect dream world the lines should be like this:

    Code:
    string fileNameToWrite = Console.ReadLine();
    using (StreamWriter sw = new StreamWriter("D:\\{0}.txt",fileNameToWrite, true))
    {
    //do something.
    }
    I can't get my head around the logic here, I'm very new to c# - so how do I make this possible?
  • Solemn
    New Member
    • Jun 2012
    • 2

    #2
    Code:
    string fileName = Console.ReadLine();
    using (StreamWriter sw = new StreamWriter("D:\\" + fileName + ".txt", true))
                {
                    sw.WriteLine("LOL");
                }
    In my frustration, I answered the question on impulse.
    It was awesome and now my problem is solved.

    Comment

    Working...