How to open a file that is inside the solution with Process.Start

1

I added my solution in C # to a folder called "files" inside that folder will be placed some standard documents that can be analyzed at the time of registering some projects.

I have a combobox in the form for the person to choose the file you want to open.

I'm trying to use this code:

Process.Start("../arquivos/teste.jpg");

But the error. It can not find the directory. I would like to know if you can put the path in this way using Process.Start .

    
asked by anonymous 29.12.2014 / 19:10

1 answer

1

Well, if you want to make an application that works in all situations, you need to ensure that it works in all situations. If you are not finding the file you want it is likely that it does not exist at all. At least not where you're looking.

I could show you how to access the desired directory in a different way but I think your problem is quite simple. And another way does not guarantee that it will solve the problem.

You are in:

C:\Users\Lucas\Documents\Visual Studio 2012\Projects\SLN_CAPRO\CAPRO\bin\Debug

When you call:

../arquivos/teste.jpg

means that you are accessing:

C:\Users\Lucas\Documents\Visual Studio 2012\Projects\SLN_CAPRO\CAPRO\bin\arquivos\teste.jpg

That's not what you say the file is:

C:\Users\Lucas\Documents\Visual Studio 2012\Projects\SLN_CAPRO\CAPRO\arquivos\teste.jpg

Then the correct one would be to access it through:

../../arquivos/teste.jpg

But you may want to configure a more complex runtime environment with ProcessStartInfo :

var processoConfig = new ProcessStartInfo() {
    WorkingDirectory = "../../arquivos",
    FileName = "teste.jpg"
}
var processo = Process.Start(processoConfig);
    
29.12.2014 / 20:08