Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Writing to text file using Path.Combine

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

    Writing to text file using Path.Combine

    Hi,

    I am using the following line of code to write to text file however the file that is being created has a different file name to the code, please see below.

    Code:
    private string    path                = Path.Combine(@"C:\quotes\", DateTime.Now.ToString("ddMMyy.ESF"));
    The file that is created has the following name;
    210113.ES9

    How can I amend the code so the output file is 210113.ESF instead?

    Regards,
    suprsnipes

    #2
    suprsnipes, I would suggest to break it up like this -

    path = Time[0].Date.ToString("ddMMyy") + ".ESF";
    path1 = Path.Combine(@"C:\quotes\", path);

    Comment


      #3
      Hi,

      Thanks for your response. I tried the suggested code I'm sure there is something I am missing but I am getting errors such as;

      Code:
      path  = Time[0].Date.ToString("ddMMyy") + ".ESF";
      path1 = Path.Combine(@"C:\quotes\", path);
      I also tried private string in front as well.

      ----
      A field initializer cannot reference the non-static field, method, or property 'NinjaTrader.Indicator.tcpcamToQuotes.path' An object reference is required for the non-static field, method, or property 'NinjaTrader.Indicator.IndicatorBase.Time.get' Class member declaration expected.
      ] expected.
      Class member declaration expected. Class member declaration expected. Class member declaration expected. Class member declaration expected.
      ----

      If someone could suggested how I could fix this I would be very grateful,

      Regards,
      suprsnipes

      Comment


        #4
        Originally posted by suprsnipes View Post
        Hi,

        Thanks for your response. I tried the suggested code I'm sure there is something I am missing but I am getting errors such as;

        Code:
        path  = Time[0].Date.ToString("ddMMyy") + ".ESF";
        path1 = Path.Combine(@"C:\quotes\", path);
        I also tried private string in front as well.

        ----
        A field initializer cannot reference the non-static field, method, or property 'NinjaTrader.Indicator.tcpcamToQuotes.path' An object reference is required for the non-static field, method, or property 'NinjaTrader.Indicator.IndicatorBase.Time.get' Class member declaration expected.
        ] expected.
        Class member declaration expected. Class member declaration expected. Class member declaration expected. Class member declaration expected.
        ----

        If someone could suggested how I could fix this I would be very grateful,

        Regards,
        suprsnipes
        From what event/method are you calling the code?

        Comment


          #5
          If anyone is interested this is how I fixed this problem...

          Code:
          #region Variables
          
          private string path1                 = @"C:\quotes\";
          private string path2                 = DateTime.Now.ToString("ddMMyy") + ".ESF";    
          
          protected override void OnBarUpdate()
          then using as follows File.AppendAllText(Path.Combine(path1, path2), code here);

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          597 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          343 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          103 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          556 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          555 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X