in my program people can open any sort of file with the method below. I got the feedback that they can open the same file more than once. Meaning having the same file open a few times at the same time. How do I prevent this? Process.Start seemed the best option but I am open to suggestions.
This question seems similar but I can't get it to work: Is there a way to check if a file is in use?
Used method:
public void ShowFile(ModelDocument model)
{
if (model != null)
{
try
{
string locationFileName = model.DocumentPath;
using (Process process = new Process())
{
ProcessStartInfo startInfo = new ProcessStartInfo();
process.StartInfo = startInfo;
startInfo.FileName = locationFileName;
process.Start();
}
}
catch (System.Exception ex)
{
//log error
}
}
}
More context:
I have a scheduler where people can attach any document/mail to an appointment.
These get copied or moved to a folder specific for that appointment. In my database I store the path and other info concerning the file. In the appointment screen they can double-click a file in a GridView to open it. These files can be anything from pdf's to msg (Mails).