Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting stream writer output file to desktop

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Setting stream writer output file to desktop

    Hello. I have done this before, but I no longer have the indies in which I have done this simple operation before.

    I would like to simply write to a text file, and the location I want to write to is my desktop. It is simply the syntax that I am missing.

    Below is an example of what I am trying to do. The first line is taken from the reference sample, which works, but it outputs the output file to my default NT directory. The commented out line, is where I would like it to go but the syntax is not correct.

    The attached pic is the error that I get in the output window.

    Code:
    		private string path 			= Cbi.Core.UserDataDir.ToString() + "OutPut.txt";
    //		private string path 			= "@C:Users\Forrest\Desktop\OutPut.txt";
    Attached Files

    #2
    Hello forrestang, and thank you for your question.

    I am including an excerpt from the following publicly available MSDN C# link. Please let us know if there are any other questions we could answer.

    Learn ways to write or append text to a file for a .NET app. Use methods from the StreamWriter or File classes to write text synchronously or asynchronously.


    Code:
    [FONT=Courier New]// Create a string array with the lines of text
    string[] lines = { "First line", "Second line", "Third line" };
    
    // Set a variable to the My Documents path.
    string mydocpath =
        Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
    
    // JDP Mon Dec 19 09:54:37 MST 2016
    // Using the path you provided instead
    mydocpath = Cbi.Core.UserDataDir.ToString() + "OutPut.txt";
    
    // Write the string array to a new file named "WriteLines.txt".
    using (StreamWriter outputFile = new StreamWriter(mydocpath + @"\WriteLines.txt")) {
        foreach (string line in lines)
            outputFile.WriteLine(line);
    }[/FONT]
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Try:
      @"C:\\Users\Forrest\Desktop\OutPut.txt";


      Originally posted by forrestang View Post
      Hello. I have done this before, but I no longer have the indies in which I have done this simple operation before.

      I would like to simply write to a text file, and the location I want to write to is my desktop. It is simply the syntax that I am missing.

      Below is an example of what I am trying to do. The first line is taken from the reference sample, which works, but it outputs the output file to my default NT directory. The commented out line, is where I would like it to go but the syntax is not correct.

      The attached pic is the error that I get in the output window.

      Code:
              private string path             = Cbi.Core.UserDataDir.ToString() + "OutPut.txt";
      //        private string path             = "@C:Users\Forrest\Desktop\OutPut.txt";

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      558 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      324 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      545 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      547 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X