Hi
I've been struggling with this for days now and I've no ideea why it doesn't work...
The story is short: I've an ASP.NET application and I wanna create a new mxd file, load some shape layers into and then save it for further referencing by a MapService.
Everything works great but saving the MapDocument. I get:
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
when trying to use Save
or
"A lock violation has occurred. (Exception from HRESULT: 0x80030021 (STG_E_LOCKVIOLATION))" when using SaveAs with the same filename
or
"Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))" when saving as different name.
I use ArcGIS 9.3 SP1 and Visual Studio 2008.
The code goes like this:
'===========================
'create the map document
Dim pMapDoc As IMapDocument
pMapDoc = New MapDocument
pMapDoc.New(fName)
pMapDoc.Save()
pMapDoc.Close()
'change the name of the data layer
pMapDoc = New MapDocument
pMapDoc.Open(fName)
Dim pMap As IMap = pMapDoc.Map(0)
pMap.Name = "Layers"
pMapDoc.Save()
pMapDoc.Close()
'add the previously loaded layers (NL and NLPoint)
If pMap.LayerCount = 0 Then cMap.SpatialReference = RE.SpatialReference
pMap.AddLayer(NL)
pMap.AddLayer(NLPoint)
'if I break here the map has the layers and stuff... so, it's ok
'try to refresh (save) the mxd
pMapDoc.Open(fName)
pMapDoc.SetActiveView(pMapDoc.Map(0)) 'do I need it?..
pMapDoc.ReplaceContents(pMap)
pMapDoc.Save(False, True)
'or
'Dim fname1 As String = "E:/AUTOMXD/my1.mxd"
'pMapDoc.SaveAs(fname1, False, True)
'End If
pMapDoc.Close()
'===========================
Just some other remarks...
1. I've granted access to the destination folder to all the possible users (SOM, SOC, WEBSERVICE, ASPNET,...)
2. WEIRD!!! 'Save' method works until adding the layers (e.g. changing the name of the group layer)
3. WEIRD!!! even thou 'Access denied', the mxd is created on file (half the size of an empty one)!!! ArcMAP crashes when trying to open it.
4. I've also tried to open an already created mxd file and save it. Same result.
5.....
Please, any of you have any idea?..
Thanks