How to check is a Map Document is already open/in use by another application

1859
3
Jump to solution
05-09-2012 05:58 AM
Highlighted
Occasional Contributor II
I am developing a standalone application in C#/VS 2010 - ArcGIS Engine 10 which will run on several computer.
All my MXD files and associated data will be stored on only one computer and accessed by all, either by my application or ArcMap which is also installed on these computers.

my problem is simple :
How can I check programmaticaly that a Map Document is not already opened by ArcMap or ArcGIS Engine ? when I test, I open my mxd with ArcMap, then execute my application which try to open, change and then save it.
I though i could use the get_IsReadOnly before saving it, but it's not working :

    IMapDocument _mapDoc = new MapDocumentClass();
    _mapDoc.Open(sFilename, string.Empty);
    if (_mapDoc.get_IsReadOnly(sFilename))          -> return "false" even if the map document is already opened in ArcMap... I was expecting "true"
    {
        _mapDoc.Close();
        return;
    }
    _mapDoc.ReplaceContents((IMxdContents)axMapControl.Map);
    _mapDoc.Save(true, false);                                                -> if already open somewhere else then I catch an Exception !
    _mapDoc.Close();

The exception is : a share violation has occured. (Exception from HRESULT: 0x80030020 (STG_E_SHAREVIOLATION))

so How can I chek if the mxd file is already opened somewhere else before working with it in my application ?
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Regular Contributor III
I don't think so.

If you are only worried about ArcMap then the ROT might help but you seem to also be concerned about tools in general.

Essentially, I think that you need to ask the OS whether or not any process has the file open.

View solution in original post

Reply
0 Kudos
3 Replies
Highlighted
Occasional Contributor II
Instead of IMapDocument::get_IsReadOnly(), a simple solution would be to check if there are lock files on the map data as in my cases I know where are stored the data and I know that each map contains at least one feature class from either shapfile, file deodatabase or personel geodatabase. so loocking for lock files should be easy.

But I would really like to know how we can simply check if the .mxd file is already open somewhere ? does ESRI not providing a simple mechanism for that ?
Reply
0 Kudos
Highlighted
Regular Contributor III
I don't think so.

If you are only worried about ArcMap then the ROT might help but you seem to also be concerned about tools in general.

Essentially, I think that you need to ask the OS whether or not any process has the file open.

View solution in original post

Reply
0 Kudos
Highlighted
Occasional Contributor II
I don't think so.

If you are only worried about ArcMap then the ROT might help but you seem to also be concerned about tools in general.

Essentially, I think that you need to ask the OS whether or not any process has the file open.


Thank you for your answer... I'll try to not go deep in OS process research, but keep your solution in mind.
Reply
0 Kudos