working with file system.

November 13, 2012 at 22:51:39
Specs: Windows 7
Am writhing an application that opens any file using a stored file path but what i want is that when a user opens a file the first time it okay but when he tries to open the same file again they should get a notification that the file is already open....

Document document;

string path;
document = (Document)dgvDocs.CurrentRow.DataBoundItem;
path = document.Documentpath;


See More: working with file system.

Report •

November 13, 2012 at 23:39:45
Have a look at the various suggestions in this thread:

Report •

November 14, 2012 at 08:09:06
Okay, here's the deal:
• There is no official way to do what you want.
• Process.Start gives you a Process object which you can use to see if the program has terminated, but you won't know the status of the file. For instance, if the user uses this program to open an Excel file, your program won't let the user open the same spreadsheet until the user closes all open spreadsheets and closes Excel.
• The unofficial way of doing what you want is using NtQuerySystemInformation, but that's prone to hanging and/or failing depending on the state of the system at any given moment. It also requires elevation. As they're undocumented, NtQuery* functions are technically implementation details so expect incompatibilities between versions of Windows. This StackOverflow thread has some useful links on the subject.
• File locks in the launcher are probably not the way to go, as it'll just prevent the launched application from opening the file, and I doubt that's what you want.
• Unicode snowman: ☃

How To Ask Questions The Smart Way

Report •
Related Solutions

Ask Question