Error: already exists.(stg_e_filealreadyexists) when using IMapDocument.Open method ?

680
2
Jump to solution
12-26-2013 06:21 PM
Highlighted
by
Occasional Contributor II
Hi everyone,

I got the errror: already exists.(stg_e_filealreadyexists) when using the method IMapDocument.Open() as below codes:

if (File.Exists (strDirectory + "\\temp.mxd"))         File.Delete(strDirectory + "\\temp.mxd"); System.IO.FileStream oFileStream = new System.IO.FileStream(strDirectory + "\\temp.mxd", FileMode.Create); oFileStream.Write(MyImage, 0, MyImage.Length); IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(strDirectory + "\\temp.mxd"); // Throw exception


Do you know why and how to fix this error ?

Thanks and regards,

Tai
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
by
Occasional Contributor II
You might try closing the stream.  The standard practice is to use a "using" statement.  Google on "filestream using statement".

I assume that you know that map documents (mxd files) are OLE structured storage.  I point this out because you did not share the code related to "MyImage".


Thanks rlwatson,

I tried to close the stream, but not successful. I think the reason is MyImage object. And I relsoved this problem.

Kind regards,

Tai

View solution in original post

Reply
0 Kudos
2 Replies
Highlighted
Regular Contributor III
You might try closing the stream.  The standard practice is to use a "using" statement.  Google on "filestream using statement".

I assume that you know that map documents (mxd files) are OLE structured storage.  I point this out because you did not share the code related to "MyImage".
Reply
0 Kudos
Highlighted
by
Occasional Contributor II
You might try closing the stream.  The standard practice is to use a "using" statement.  Google on "filestream using statement".

I assume that you know that map documents (mxd files) are OLE structured storage.  I point this out because you did not share the code related to "MyImage".


Thanks rlwatson,

I tried to close the stream, but not successful. I think the reason is MyImage object. And I relsoved this problem.

Kind regards,

Tai

View solution in original post

Reply
0 Kudos