none
how to open a file but without knowing the directory? C#

    Question

  • Hello I am trying to open a file with System.Diagnostics.Process.Start(). 

    I know the file directory and name but I need to just know the name.

    Like:

    System.Diagnostics.Process.Start(@"Application\Folder\updater.exe");

    But it says it does not know the directory. I do not need the directory cause other people are going to use this app. Anyone know what to do?

    No like I said, this is not just for me other people will use this app. Please do not respond by saying 

    "Just add "C:\Yourself\Appliction..." thats not what I need I need to know how to open this app just using that directory. No extensions.

    Wednesday, April 17, 2019 2:35 PM

All replies

  • Hello,

    If  this has to do with your app itself the AppDomain.CurrentDomain.BaseDirectory (which is not in .NET core) points to your app folder. Now given just "Application\Folder\updater.exe" there is no way to figure out what the parent folders are unless there is a point of reference like with AppDomain or via Directory.GetCurrentDirectory. Not sure if this is helpful or not but thought it prudent to provide information.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, April 17, 2019 6:10 PM
    Moderator
  • Hi Atks27,

    How do you publish the app to other people? If you just copy the "exe" in the folder "bin/Release", the app will not be able to determine the relative path you specified.

    Maybe you can try to publish it via ClickOnce or VS Installer, copy "updater.exe" to the appropriate directory while installing the app.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 18, 2019 1:41 AM
    Moderator
  • You could also use Application.StartupPath, like this:

    System.Diagnostics.Process.Start(Application.StartupPath + @"\updater.exe");

    I prefer it, and according to this StackOverflow question, StartupPath is the "best". But, read the link yourself:

    https://stackoverflow.com/questions/35575688/preference-between-application-startuppath-and-appdomain-currentdomain-basedirec


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Thursday, April 18, 2019 1:48 AM
  • Hi Atks27,

    Is your problem solved? If so, please post "Mark as answer" to the appropriate answer.So that it will help other members to find the solution quickly if they face the similar issue.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, April 23, 2019 5:42 AM
    Moderator