Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 jeronymite, 04-12-2024, 04:26 PM
      3 responses
      43 views
      0 likes
      Last Post jeronymite  
      Started by frankthearm, Today, 09:08 AM
      4 responses
      9 views
      0 likes
      Last Post frankthearm  
      Started by yertle, Today, 08:38 AM
      5 responses
      15 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by adeelshahzad, Today, 03:54 AM
      3 responses
      16 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by bill2023, Yesterday, 08:51 AM
      6 responses
      27 views
      0 likes
      Last Post NinjaTrader_Erick  
      Working...
      X