Find the location of my application's executable in WPF (C# or vb.net)?

前端 未结 7 1363
借酒劲吻你
借酒劲吻你 2020-12-08 04:02

How can I find the location of my application\'s executable in WPF (C# or VB.Net)?

I\'ve used this code with windows forms:

Application.ExecutablePat         


        
7条回答
  •  误落风尘
    2020-12-08 04:26

    Based on others answers, here's an example that shows how to remove the executable name from the path and combine the result with some subfolder and filename:

    at my updated version of Hotspotizer (http://github.com/birbilis/Hotspotizer), I've just added support for loading a Gesture Collection file at startup, if found at Library\Default.hsjson, by using the following code:

    const string GESTURE_COLLECTION_LIBRARY_PATH = "Library"
    const string DEFAULT_GESTURE_COLLECTION = "Default.hsjson"
    
    //...
    
    LoadGestureCollection(
      Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
      GESTURE_COLLECTION_LIBRARY_PATH,
      DEFAULT_GESTURE_COLLECTION));
    

提交回复
热议问题