Home > OS >  How to get directory of an xls file C#
How to get directory of an xls file C#

Time:05-29

I need to make a program that reads the columns of an excel. But for that, I need to get the path (directory) of this excel. What prevents me from doing this, is that I didn't want to leave my local directory fixed, because if someone downloads the file on another machine, they will need to change the path. I appreciate if anyone can help me with this!

enter image description here

I should mention that a file in the executing directory can be read but not written (without elevated permissions). If the file is user data then refer to the answer that uses an Environment variable:

var appdata = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)

  •  Tags:  
  • c#
  • Related