常用方法

一,获取Mxd地图文档的路径
/// <summary>
        /// 获取Mxd地图文档的路径
        /// </summary>
        /// <param name="MapControl"></param>
        private string OpenMxFile()
        {
            string mxdFile = "" ;
 
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = @"D:Program Files (x86)ArcGISDeveloperKit10.2Samplesdata";
            ofd.Filter = "Map Documents(*.Mxd)|*.mxd";
 
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                mxdFile = ofd.FileName;
 
            }
 
            return mxdFile;
        }


二,获取ShapeFile的路径
/// <summary>
        /// 获取ShapeFile的路径
        /// </summary>
        /// <returns></returns>
        private string[] OpenShapeFile()
        { 
          string[] ShpFile = new string[2];
          OpenFileDialog ofd = new OpenFileDialog();
          ofd.Title = "打开shp文件";
          ofd.InitialDirectory = @"D:Program Files (x86)ArcGISDeveloperKit10.2Samplesdata";
          ofd.Filter = "Shp文件(*.shp)|*.shp";
 
          if (ofd.ShowDialog()== System.Windows.Forms.DialogResult.OK)
          {
              string ShapePath = ofd.FileName;
              
              //利用"\"将文件路径分成两部分
              int position = ShapePath.LastIndexOf("\");
              string filePath = ShapePath.Substring(0,position);
              string fileName = ShapePath.Substring(position+1);
              ShpFile[0] = filePath;
              ShpFile[1] = fileName;
 
          }
 
          return ShpFile;
        }


原文地址:https://www.cnblogs.com/Robert-huge/p/5855564.html