简体   繁体   中英

How to get the installed application location in c#?

I have created a WPF application in my application i'm specifying the default path for the installation location suppose, XYZ is my application, "C:\\MyApplication\\XYZ\\" this is my specified default location where my application gets installed, my application creates a folder dynamically which will be created during the installation of the application in the installed directory, i want when user uninstalls the application then my entire folder(XYZ) has to be deleted i tried many ways but i'm not getting it Please any one give suggestion it will helps me a lot.

Here is what i have tried :-

string filepath = String.Format(@"data\local", Environment.CurrentDirectory);
public override void Uninstall(IDictionary savedState)
{
    try
    {               
        base.Uninstall(savedState);
        // If i Hard code this i.e if i give direct path(C:\MyApplication\XYZ\) 
        // then it's getting deleted but if user installs application in other 
        // location it gets fail.
        Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory(
          filepath, 
          Microsoft.VisualBasic.FileIO.DeleteDirectoryOption.DeleteAllContents); 
    }
    catch(Exception e)
    {
        MessageBox.Show(e);
    }
}

Application installation is not something that we need to manage manually in the .NET Framework. It provides multiple installation options, so you do not have to manually install or uninstall your applications. The two main installation options the Framework are:

  1. ClickOnce Deployment
  2. Setup Projects

As there is far to much to discuss here, please follow the links to find out more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM