I am using a strategy to log stats and generate a report. At the end of a trading period (3 months) I need to export/write to a .csv file. Before I get too far down the debug rabbit hole, I'd like to ask if anyone has any insight on the error shown below in the event it's an issue with file permissions inside of Windows. Here's the error:
As I go through the path C:\Program Files (x86)\NinjaTrader 8\bin64, RMB on each folder > properties, they all show as Read-only.
I think this is an issue. IIf I change this, then hit Okay, it looks like it takes, but if I RMB > properties again they always go back to Read-only. I even went back to the root folder and tried this. It sat there for about 5 minutes "changing" everything, but again, when I RMB > properties, they're all back to Read-Only. I think this could the source of the problem, I just don't know how to fix it.
Any assistance from the community would be greatly appreciated. Thank you for your time and help in advance!
Nathan.
Other potentially relevant information:
- The code does fine without my ExportData function, and prints to Ninja's Output window without error. However, I need to do this on a much larger scale, so I want to send it to a .csv for further analysis.
- ExportData code...
Code:public static class ExportData { // https://gist.github.com/luisdeol/c2c276796a92c8e3246ce2cd3e17e1df public static void ExportCsv<T>(List<T> genericList, string fileName) { var sb = new StringBuilder(); var basePath = AppDomain.CurrentDomain.BaseDirectory; var finalPath = Path.Combine(basePath, fileName + ".csv"); var header = ""; var info = typeof(T).GetProperties(); if (!File.Exists(finalPath)) { // If the file does no exist, then create it, and add a header row. var file = File.Create(finalPath); file.Close(); foreach (var prop in typeof(T).GetProperties()) { header += prop.Name + ", "; } header = header.Substring(0, header.Length - 2); sb.AppendLine(header); TextWriter sw = new StreamWriter(finalPath, true); sw.Write(sb.ToString()); sw.Close(); } foreach (var obj in genericList) { // Adds each value of info to a line, and puts a "," to serparate each. Rinse and repeat sb = new StringBuilder(); var line = ""; foreach (var prop in info) { line += prop.GetValue(obj, null) + ", "; } line = line.Substring(0, line.Length - 2); sb.AppendLine(line); TextWriter sw = new StreamWriter(finalPath, true); sw.Write(sb.ToString()); sw.Close(); } } }

Comment