C# Executable Executing directory

前端 未结 8 2003
庸人自扰
庸人自扰 2020-12-11 02:38

What is the best method of getting the path the C# executable is running from?

I need to use it for temp folders etc and currently I\'m using:

Path.G         


        
8条回答
  •  无人及你
    2020-12-11 03:15

    For temp folders etc. you should NOT use the executing directory for security reasons... MS has something built-in for this:

    You can use ApplicationData (for roaming users) or LocalApplicationData (for non-roaming users) or CommonApplicationData (for non-user-related things) from Environment.SpecialFolder - anything (files+folders) you create within those folders is already setup with the needed permissions/rights for the user running you app - nobody else (except perhaps Administrator) can go there... to make it even more secure you could encrypt data you put there...

    see http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx

提交回复
热议问题