PDA

View Full Version : Saving a Map into a Database



xonji
12-14-2011, 07:54 AM
Hi,

I want to save my actual map into a .ptm and store it in my Oracle Database my Only Problem is that after I saved my map, the .ptm file cant be accessed by other Processes like a filestream operation. But I have to save that .ptm as a BLOB in my DB so how can I stop Mappoint from accessing my actual saved map ?

Code:



public String[] SpeicherMapOhneDialog()
{
thisControl.SaveMapAs(filePathPtm);
Console.WriteLine("Saved");
thisControl.ActiveMap.Saved = true;

String strBinaryPtm;
String strBinaryCsv;
String[] res = new String[2];

//PTM-Stream
{
FileStream fs = new FileStream(filePathPtm, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);

byte[] ptmFile = br.ReadBytes((int)fs.Length);

br.Close();
fs.Close();

strBinaryPtm = Convert.ToBase64String(ptmFile);
}

//CSV-Stream
{
FileStream fsCsv = new FileStream(filePathCsv, FileMode.Open, FileAccess.Read);
BinaryReader brCsv = new BinaryReader(fsCsv);

byte[] csvFile = brCsv.ReadBytes((int)fsCsv.Length);

brCsv.Close();
fsCsv.Close();

strBinaryCsv = Convert.ToBase64String(csvFile);
}


res[0] = strBinaryPtm;
res[1] = strBinaryCsv;

return res;

}



Thanks in advance for your help !
xonji

Eric Frost
12-14-2011, 09:11 AM
I can suggest some stuff, let us know how it goes.

1. close the MapPoint application.
2. copy the file first, I think it will let you do this without closing MapPoint, but not sure.
3. do a second "Save As" to a temporary/dummy location such as c:\temp\test.ptm, then the MapPoint application will be locking the new file.

hope this helps! let us know how it goes,

Eric

xonji
12-14-2011, 09:28 AM
thx eric ! I'll try it out soon :) and post my review!

b.r. xonji

xonji
12-22-2011, 04:10 AM
Saving the Map twice works like a Charm !!!




thisControl.SaveMapAs(filePathPtm);
Console.WriteLine("Saved");
thisControl.ActiveMap.Saved = true;

thisControl.SaveMapAs(@"W:\dummy.ptm");

Process thisProcess = Process.GetCurrentProcess();

thisProcess.Refresh();


Thanks 4 the Help !

Eric Frost
12-22-2011, 10:49 AM
Sure, thanks for the follow up, glad to hear you got it working!

Eric