Open, save, and save an mxd File

Source: Internet
Author: User

Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;
Using ESRI. ArcGIS. ADF;
Using ESRI. ArcGIS. Controls;
Using ESRI. ArcGIS. SystemUI;

Using ESRI. ArcGIS. esriSystem;
Using ESRI. ArcGIS. Geometry;
Using ESRI. ArcGIS. Carto;
Using ESRI. ArcGIS. Display;

1. Global Variables
IMapDocument mapDoc;
2. initialize global variables in the constructor
MapDoc = new MapDocumentClass ();
3. Open the mxd File
Private void OpenMxd (){

Try
{
// Select the MXD file in the open file dialog box
OpenFileDialog openFileDialog2;
OpenFileDialog2 = new OpenFileDialog ();
OpenFileDialog2.Title = "Open mxd file ";
OpenFileDialog2.Filter = "map document (*. mxd) | *. mxd ";
OpenFileDialog2.ShowDialog ();
String sFilePath = openFileDialog2.FileName;

// Load the data into pMapDocument and associate it with the map control.
MapDoc. Open (sFilePath ,"");
AxMapControl1.Map. ClearLayers ();
Int I;
For (I = 0; I <= mapDoc. MapCount-1; I ++)
{
// An IMapDocument object can have multiple Map objects and traverse each map object
AxMapControl1.Map = mapDoc. get_Map (I );

}
// Refresh the map
AxMapControl1.Refresh ();
}
Catch (Exception ex)
{
MessageBox. Show (ex. ToString ());
}

}
4. Save the mxd File
Private void SaveMxd ()
{
If (mapDoc. get_IsReadOnly (mapDoc. DocumentFilename) = true)
{
MessageBox. Show ("this file is read-only! ");
Return;
}
MapDoc. Save (mapDoc. UsesRelativePaths, true );
MessageBox. Show ("saved successfully! ");
}

5. Save as an mxd File
Private void SaveAsMxd ()
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog ();
SaveFileDialog1.Title = "Saving mxd Files ";
SaveFileDialog1.Filter = "map document (*. mxd) | *. mxd ";
SaveFileDialog1.ShowDialog ();
String sFilePath = saveFileDialog1.FileName;
If (sFilePath = "")
{
Return;
}
If (sFilePath = mapDoc. DocumentFilename)
{
SaveDocument ();
}
Else
{
MapDoc. SaveAs (sFilePath, true, true );
MessageBox. Show ("saved successfully! ");
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.