0

I have created a simple windows form application to create a excel file and logging some debugging information.

this is my code when creating excel file

xlWorkBook.SaveAs(filePath, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);

and this is the code when logging some debugging information

 using (System.IO.StreamWriter file = new System.IO.StreamWriter("logFile.log", true))

I have publish the application and install it in my machine to test out the location of both files. I found my excel file in the Document folder while the log file in C:\Users\ME\AppData\Local\Apps\2.0\METYACXG.8BW\3MBVM2YL.M9V\bill..tion_974a70d1e552787b_0001.0000_c89a52caddc0075b

I wonder is this the standard way or best practice?

WenHao
  • 1,183
  • 1
  • 15
  • 46

1 Answers1

1

The Documents (or My Documents) folder is the standard and recommended folder for saving data files such as those from Microsoft Office applications.

The folder at:

C:\Users\user_account\AppData\Local\Apps\2.0\

Is the file cache for ClickOnce applications on Vista and later OS's.

For your log files and any other persistent application data files that you may be creating such as ini or xml configuration files, they should be saved into a custom folder of the application's name in the local application data folder at:

C:\Users\user_account\AppData\Local\your_app_name\

The location of the local application data folder is retrieved using:

System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData);

If your application is being deployed on networks where the user accounts use roaming profiles then you will have to use a custom folder of the application's name in the roaming folder which is at:

C:\Users\user_account\AppData\Roaming\your_app_name\

And is retrieved using:

System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);

Also see stackoverflow: Best place to store configuration files and log files on Windows for my program? And stackoverflow: where to save application logs

.

Community
  • 1
  • 1
deegee
  • 1,553
  • 14
  • 13