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

1618
2
Jump to solution
12-26-2013 06:21 PM
TaiBui
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
0 Kudos
1 Solution

Accepted Solutions
TaiBui
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

0 Kudos
2 Replies
RichardWatson
Frequent Contributor
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".
0 Kudos
TaiBui
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
0 Kudos