C# File path on other machines

Asked

Viewed 32 times

-1

I created a program that opens some powerpoit files. However I came across a question. Excerpt from the code:

private void FitaBackupToolStripMenuItem_Click(object sender, EventArgs e)
        {          System.Diagnostics.Process.Start(@"C:\Users\abner\source\repos\PrjTarefas\PrjTarefas\apresentacoes\FitaBackup.ppsx");
        }

I realized that even if I took the file "Fitabackup.ppsx" together, the machine that would put the program, I needed to have all the way "C: Users Abner source Repos " before arriving in the program folder "Prjtarefas" that I would put in the other machine.

So, is there any way to make this path more generalized, avoiding the "source" and "Repos" folder for example? Because from "Prjtarefas" is guaranteed to find the file, the problem is the previous path.

1 answer

1


I believe that using Appdomain.CurrentDomain.Basedirectory you solve this problem.

I used this resource in the example below and it worked.

inserir a descrição da imagem aqui

  • 1

    It worked, but I have another problem. My code looks like this: private void Zera59296929toolstripmenuitem_click(Object Sender, Eventargs and) { string path = $"{Appdomain.CurrentDomain.Basedirectory}Prjtarefas presentations"; System.Diagnostics.Process.Start(path + "Zerar5929.ppsx"); } Returns the path: C: Users Abner source Prjtarefas Prjtarefas bin Debug Prjtarefas presentations But the file is in the path: C: Users Abner source Prjtarefas Prjtarefas presentations How do I go back 2 directories?

  • 1

    Sorry Ramon, I was confusing myself with the address, I was able to solve the problem. Thanks for helping!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.