这个工作看起来容易,但其实不然。经过测试,必须通过下面的代码才可以得到正确的路径

AppDomain.CurrentDomain.SetupInformation.ApplicationBase

 

有的朋友会用Environment.CurrentDirectory,但其实因为windows service的特殊性,Environment.CurrentDirectory永远指向system32这个目录。相对来说,在Console App中Environment.CurrentDirectory则是有效的

有点朋友会说,用Applicatio.StartupPath,但这个属性只有在Windows Forms程序里面才有,而在windows service中则没有。

相关文章:

  • 2022-12-23
  • 2021-10-04
  • 2022-12-23
  • 2021-12-10
  • 2021-09-11
  • 2022-02-07
  • 2022-01-28
  • 2022-12-23
猜你喜欢
  • 2022-03-06
  • 2021-08-22
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
  • 2021-09-19
相关资源
相似解决方案