Search code examples
c#.netprocess.start

Get file from Process.Start()-Method


I'm trying to retrieve a file from the Process.Start()-Method.

Following scenario is given:

I obtain a link from a third party program. This link can be a UNC-path, direct link to PDF/JPG/TIF-files, such as "www.certainServer.de/test.pdf", as well as link to programs on the server, which return a special file type, such as "www.certainServer.de/test.aspx".

I open the file like this

Process.Start(_path)

If the link is like "www.certainServer.de/test.aspx" the returned file is automatically downloaded to the deposited download folder.

Is there a opportunity to retrieve the downloaded file or the path to the downloaded file?

The returned Process-object from the Process.Start()-Method doesn't seem to be helpful.


Solution

  • Process.Start does not necessarily download a file. It simply starts a process. You just as easily could start Notepad, which has no side effects (except, of course, what you do with notepad once it's started). If the process you start (in your case, calling a web page) has external effects, the process engine knows nothing about it.

    It sounds like you know where the file is supposed to be deposited, so you could use something like a FileSystemWatcher to be alerted when a new file is added (which doesn't necessarily mean it came from your process, though) or get a list of files before and after the process is run.

    But there's nothing inherent to System.Process to definitively know what that process did.

    Another option might be to call the URL from your code (using WebClient or something similar) and capturing the result (which might be a file, or just a web page, depending on the URL). It's not as general as starting a process and letting the default browser handle the download, but it would capture the results more definitively.