AnsweredAssumed Answered

Open an existing map

Question asked by MannyJohn on Nov 1, 2019
Latest reply on Nov 6, 2019 by MannyJohn

I'm trying to open a map located in a project folder, however when i try using this code i get Exception Unhandled  error 

System.NullReferenceException: 'Object reference not set to an instance of an object.' mapProjectItem was null.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ArcGIS.Core.CIM;
using ArcGIS.Core.Data;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Catalog;
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Editing;
using ArcGIS.Desktop.Extensions;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.Dialogs;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;

namespace AddData
    internal class Button4 : Button
        protected override void OnClick()
                var mapProjectItems = Project.Current.GetItems<MapProjectItem>();
                var mapProjectItem = mapProjectItems.FirstOrDefault(mpi => mpi.Name.Equals("Map1"));
                Map map = mapProjectItem.GetMap();