0

So I have a solution witch has two different projects(for example one of them is admin and one of them is presentation). it means I have two .exe files. My current project is for example presentation but I want the directory of the other one(admin)

 AppDomain.CurrentDomain.BaseDirectory

this code gives me the current project directory. one way is to back(./) and reach to the other project but it will be too much hard code. Is there any better ways to do it

Danial
  • 23
  • 8
  • 1
    why should that matter? because you will have one execution directory where all files/folders should be copied to, so everything in project B should be copied next to the *.exe which is (most likely) Project A. – Rand Random Jun 26 '23 at 15:36
  • that's the problem. I have two execution directories. one of them is admin and the other one is presentation – Danial Jun 26 '23 at 15:38
  • 1
    okay... what if a user places project a.exe in c:\foo\ and project b.exe in c:\program files\bar ? since they are two seperate application, one could assume they can run independently? – Rand Random Jun 26 '23 at 15:47
  • 1
    Change the output directories of the projects to the same location so executables are in the same folder? That is then (presumably) the same as when you deploy the applications later? Or do you explicitly plan a different deployment strategy then say so. – Ralf Jun 26 '23 at 15:47
  • I don't understand what you mean by admin vs presentation. What types of projects are these? Two projects can be in the same solution, and if you want to share code between the two, then one project should reference the class library's `.dll` that it wants to use. If you need to manipulate files in the other project's directory or something, then relative pathing with `./` is your best option – Narish Jun 26 '23 at 15:47
  • OK, So if I want to explain it with no examples. This is my real issue: I have an admin witch is a wpf application that is only for the admin and the presentation witch is also a wpf application and its for the users so I want to show the files that have uploaded in the admin(by admin) to the presentation(for users). So I need the directory of admin in presentation. – Danial Jun 26 '23 at 15:55
  • why don't they have a shared directory then? eg. `CommonProgramFiles` https://learn.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=net-7.0 ? or if you want to use a custom directory let the user pick one, write it into eg. registry – Rand Random Jun 26 '23 at 15:59
  • "so I want to show the files that have uploaded in the admin" So its not about the applications but you want to see data from a shared folder so you need a configuration where that folder with the data you want to use in both application can be found? – Ralf Jun 26 '23 at 16:14

1 Answers1

1

Generally solutions/projects are design time concepts, at run time these are simply independent exes that you can put wherever you want (like I assume u will be putting it in say c:\xxx\Admin\Project1.exe and c:\xxx\Presentation\Project2.exe). If so there are many possible ways to access these during runtime, some include:

  • Relative path: like you mentioned using ..\ syntax
  • Some form of config: app.config/other config file (local directory or appdata etc)/registry
  • Advanced modes: maybe IPC (works if both exe's are running)
subdeveloper
  • 1,381
  • 8
  • 21
  • can you explain the IPC one more or maybe send an article if u don't mind? – Danial Jun 26 '23 at 16:00
  • 1
    @Danial - we are currently using `gRpc` for our interprocess communication needs - https://learn.microsoft.com/en-us/aspnet/core/grpc/interprocess?view=aspnetcore-7.0 – Rand Random Jun 26 '23 at 16:03
  • Sure, IPC stands for Inter process communication, and its any way through which 2 processes can communicate. see for simple example and some links [here](https://stackoverflow.com/questions/528652/what-is-the-simplest-method-of-inter-process-communication-between-2-c-sharp-pro) – subdeveloper Jun 26 '23 at 16:04