How do I get Bin Path?

后端 未结 6 1424
时光取名叫无心
时光取名叫无心 2020-12-25 09:32

I need to the the bin path of the executing assembly. How do you get it? I have a folder Plugins in the Bin/Debug and I need to get the location

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-25 10:01

    Here is how you get the execution path of the application:

    var path = System.IO.Path.GetDirectoryName( 
          System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
    

    MSDN has a full reference on how to determine the Executing Application's Path.

    Note that the value in path will be in the form of file:\c:\path\to\bin\folder, so before using the path you may need to strip the file:\ off the front. E.g.:

    path = path.Substring(6);
    

提交回复
热议问题