I have this superb awesome WPF application where users, among several other things, upload files that then are stored in a database (requirement). At anytime a user running this application can click on a file hyperlink to open the file at his local computer. In order to do this I simply use:
var process = Process.Start(tempPath);
I deserialize the bytes stored in database and write a temp file on an specific folder. Another requirement was that if the user performs any changes to the temp file, he can simply click save in whatever application is using and the file then should be automatically saved to the database. I use FileSystemWatcher to know if the temp file was modified and the following to keep track of the process:
await process.WaitForExitAsync(async () =>
{
if(!wasModified) return;
this.SetBusy();
var path = _workDocumentsOpened[work.Id];
_workDocumentsOpened.Remove(work.Id);
await work.SetDocumentAsync(path, work.DocumentFileName);
File.Delete(path);
this.SetNotBusy();
});
This works fine most of the time. However since there is no restriction in the type of file (extension) that the user can upload, if a user downloads the file and does not have a default application configured for it then the following Windows dialog is shown:
The problem is that by that time Process.Start returned null =( and so far I have not been able to figure out how to detect which process is selected by the user to open the file or if the operation is simply cancelled.
Any help is appreciated