LINQPad script directory?

爱⌒轻易说出口 提交于 2019-12-04 08:49:29

问题


Does anyone know how to get hold of the path to the directory where the LINQPad script file (.linq) resides?

Or to the script itself for that matter.

Note that I'm not talking about the location of the "My Queries" folder, the one shown inside LINQPad.

I can save a .linq file anywhere on disk, and open it by double-clicking on it.

For instance, if I save the file to C:\Temp\Test.linq, and execute the program, I'd like to have either C:\Temp or C:\Temp\Test.linq.

Basically I'd like something akin to Environment.CurrentDirectory or Assembly.GetEntryAssembly().Location, just for the .linq file.

Things I've tried:

  • Looking through environment variables
  • Looking through the LINQPad assembly that is given to my script
  • Throwing an exception and looking at the stacktrace (contains a link to a temporary copy of my script somewhere else)
  • Environment.CommandLine.Dump(); - gives LINQPad executable
  • Environment.CurrentDirectory.Dump(); - gives C:\windows\system32
  • Assembly.GetExecutingAssembly().Location.Dump(); - gives temp directory

回答1:


I've just added a feature to address this. You can test it now by downloading the 2.27.1 or 4.27.1 beta build.

To get the current query's folder, use the following expression:

Path.GetDirectoryName (Util.CurrentQueryPath)



回答2:


I presume you mean programatically and not through the UI itself.

The path to the linq file directory is held in

%APPDATA%\LINQPad\querypath.txt



来源:https://stackoverflow.com/questions/3802779/linqpad-script-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!