//Create an empty project. The project will be created in the default folder//It will be named MyProject1, MyProject2, or similar...await Project.CreateAsync();
Create a new project with specified name
//Settings used to create a new projectCreateProjectSettingsprojectSettings=new CreateProjectSettings(){//Sets the name of the project that will be createdName=@"C:\Data\MyProject1\MyProject1.aprx"};//Create the new projectawait Project.CreateAsync(projectSettings);
Create new project using Pro's default settings
//Get Pro's default project settings.vardefaultProjectSettings= Project.GetDefaultProjectSettings();//Create a new project using the default project settingsawait Project.CreateAsync(defaultProjectSettings);
New project using a custom template file
//Settings used to create a new projectCreateProjectSettingsprojectSettings=new CreateProjectSettings(){//Sets the project's nameName="New Project",//Path where new project will be stored inLocationPath=@"C:\Data\NewProject",//Sets the project template that will be used to create the new projectTemplatePath=@"C:\Data\MyProject1\CustomTemplate.aptx"};//Create the new projectawait Project.CreateAsync(projectSettings);
Create a project using template available with ArcGIS Pro
//Settings used to create a new projectCreateProjectSettingsproTemplateSettings=new CreateProjectSettings(){//Sets the project's nameName="New Project",//Path where new project will be stored inLocationPath=@"C:\Data\NewProject",//Select which Pro template you like to useTemplateType= TemplateType.Catalog
//TemplateType = TemplateType.LocalScene//TemplateType = TemplateType.GlobalScene//TemplateType = TemplateType.Map};//Create the new projectawait Project.CreateAsync(proTemplateSettings);
Open an existing project
//Opens an existing project or project packageawait Project.OpenAsync(@"C:\Data\MyProject1\MyProject1.aprx");
Get the Current project
//Gets the current projectvarproject= Project.Current;
Get location of current project
//Gets the location of the current project; that is, the path to the current project file (*.aprx) stringprojectPath= Project.Current.URI;
//Saves the projectawait Project.Current.SaveAsync();
Check if project needs to be saved
//The project's dirty state indicates changes made to the project have not yet been saved. boolisProjectDirty= Project.Current.IsDirty;
SaveAs project
//Saves a copy of the current project file (*.aprx) to the specified location with the specified file name, //then opens the new project fileawait Project.Current.SaveAsAsync(@"C:\Data\MyProject1\MyNewProject1.aprx");
Close a project
//A project cannot be closed using the ArcGIS Pro API. //A project is only closed when another project is opened, a new one is created, or the application is shutdown.
How to add a new map to a project
await QueuedTask.Run(()=>{//Note: see also MapFactory in ArcGIS.Desktop.Mappingvarmap= MapFactory.Instance.CreateMap("New Map", MapType.Map, MapViewingMode.Map, Basemap.Oceans); ProApp.Panes.CreateMapPaneAsync(map);});
Add a folder connection item to the current project
//Adding a folder connectionstringfolderPath="@C:\\myDataFolder";varfolder=await QueuedTask.Run(()=>{//Create the folder connection project itemvaritem= ItemFactory.Instance.Create(folderPath)as IProjectItem;//If it is successfully added to the project, return it otherwise nullreturn Project.Current.AddItem(item)? item as FolderConnectionProjectItem :null;});//Adding a Geodatabase:stringgdbPath="@C:\\myDataFolder\\myData.gdb";varnewlyAddedGDB=await QueuedTask.Run(()=>{//Create the File GDB project itemvaritem= ItemFactory.Instance.Create(gdbPath)as IProjectItem;//If it is successfully added to the project, return it otherwise nullreturn Project.Current.AddItem(item)? item as GDBProjectItem :null;});
Get all project items
IEnumerable<Item>allProjectItems= Project.Current.GetItems<Item>();foreach(var pi in allProjectItems){//Do Something }
Get all "MapProjectItems" for a project
IEnumerable<MapProjectItem>newMapItemsContainer= project.GetItems<MapProjectItem>();await QueuedTask.Run(()=>{foreach(var mp in newMapItemsContainer){//Do Something with the map. For Example:MapmyMap= mp.GetMap();}});
IEnumerable<StyleProjectItem>newStyleItemsContainer=null;newStyleItemsContainer= Project.Current.GetItems<StyleProjectItem>();foreach(var styleItem in newStyleItemsContainer){//Do Something with the style.}
IEnumerable<GDBProjectItem>newGDBItemsContainer=null;newGDBItemsContainer= Project.Current.GetItems<GDBProjectItem>();foreach(var GDBItem in newGDBItemsContainer){//Do Something with the GDB.}
IEnumerable<ServerConnectionProjectItem>newServerConnections=null;newServerConnections= project.GetItems<ServerConnectionProjectItem>();foreach(var serverItem in newServerConnections){//Do Something with the server connection.}
//Gets all the folder connections in the current projectvarprojectFolders= Project.Current.GetItems<FolderConnectionProjectItem>();foreach(var FolderItem in projectFolders){//Do Something with the Folder connection.}
Get a specific folder connection
//Gets a specific folder connection in the current projectFolderConnectionProjectItemmyProjectFolder= Project.Current.GetItems<FolderConnectionProjectItem>().FirstOrDefault(folderPI => folderPI.Name.Equals("myDataFolder"));
Remove a specific folder connection
// Remove a folder connection from a project; the folder stored on the local disk or the network is not deletedFolderConnectionProjectItemfolderToRemove= Project.Current.GetItems<FolderConnectionProjectItem>().FirstOrDefault(myfolder => myfolder.Name.Equals("PlantSpecies"));if(folderToRemove!=null)
Project.Current.RemoveItem(folderToRemove as IProjectItem);
//Gets all the layouts in the current projectvarprojectLayouts= Project.Current.GetItems<LayoutProjectItem>();foreach(var layoutItem in projectLayouts){//Do Something with the layout}
//Gets all the GeoprocessingProjectItem in the current projectvarGPItems= Project.Current.GetItems<GeoprocessingProjectItem>();foreach(var tbx in GPItems){//Do Something with the toolbox}
Search project for a specific item
List<Item>_mxd=newList<Item>();//Gets all the folder connections in the current projectvarallFoldersItem= Project.Current.GetItems<FolderConnectionProjectItem>();if(allFoldersItem!=null){//iterate through all the FolderConnectionProjectItems foundforeach(var folderItem in allFoldersItem){//Search for mxd files in that folder connection and add it to the List<T>//Note:ArcGIS Pro automatically creates and dynamically updates a searchable index as you build and work with projects. //Items are indexed when they are added to a project.//The first time a folder or database is indexed, indexing may take a while if it contains a large number of items. //While the index is being created, searches will not return any results.
_mxd.AddRange(folderItem.GetItems());}}
Get the Default Project Folder
//Get Pro's default project settings.vardefaultSettings= Project.GetDefaultProjectSettings();vardefaultProjectPath= defaultSettings.LocationPath;if(defaultProjectPath==null){// If not set, projects are saved in the user's My Documents\ArcGIS\Projects folder;// this folder is created if it doesn't already exist.defaultProjectPath= System.IO.Path.Combine(
System.Environment.GetFolderPath(
Environment.SpecialFolder.MyDocuments),@"ArcGIS\Projects");}
Refresh the child item for a folder connection Item
varcontentItem= Project.Current.GetItems<FolderConnectionProjectItem>().First();//var contentItem = ...//Check if the MCT is required for Refresh()if(contentItem.IsMainThreadRequired){//QueuedTask.Run must be used if item.IsMainThreadRequired//returns true
QueuedTask.Run(()=> contentItem.Refresh());}else{//if item.IsMainThreadRequired returns false, any//thread can be used to invoke Refresh(), though//BackgroundTask is preferred.
contentItem.Refresh();//Or, via BackgroundTask
ArcGIS.Core.Threading.Tasks.BackgroundTask.Run(()=> contentItem.Refresh(), ArcGIS.Core.Threading.Tasks.BackgroundProgressor.None);}
Get Item Categories
// Get the ItemCategories with which an item is associatedItemgdb= ItemFactory.Instance.Create(@"E:\CurrentProject\RegionalPolling\polldata.gdb");List<ItemCategory>gdbItemCategories= gdb.ItemCategories;
Using Item Categories
// Browse items using an ItemCategory as a filterIEnumerable<Item>gdbContents= gdb.GetItems();IEnumerable<Item>filteredGDBContents1= gdbContents.Where(item => item.ItemCategories.OfType<ItemCategoryDataSet>().Any());IEnumerable<Item>filteredGDBContents2=new ItemCategoryDataSet().Items(gdbContents);
//GetItems searches project contentvarmap= Project.Current.GetItems<MapProjectItem>().FirstOrDefault(m => m.Name =="Map1");varlayout= Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(m => m.Name =="Layout1");varfolders= Project.Current.GetItems<FolderConnectionProjectItem>();varstyle= Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name =="ArcGIS 3D");//Find item uses a catalog path. The path can be to a file or datasetvarfcPath=@"C:\Pro\CommunitySampleData\Interacting with Maps\Interacting with Maps.gdb\Crimes";varpdfPath=@"C:\Temp\Layout1.pdf";varimgPath=@"C:\Temp\AddinDesktop16.png";varfc= Project.Current.FindItem(fcPath);varpdf= Project.Current.FindItem(pdfPath);varimg= Project.Current.FindItem(imgPath);
Select an item in the Catalog pane
//Get the catalog pane
ArcGIS.Desktop.Core.IProjectWindow projectWindow= Project.GetCatalogPane();//or get the active catalog view...//ArcGIS.Desktop.Core.IProjectWindow projectWindow = Project.GetActiveCatalogWindow();//eg Find a toolbox in the projectstringgpName="Interacting with Maps.tbx";vartoolbox= Project.Current.GetItems<GeoprocessingProjectItem>().FirstOrDefault(tbx => tbx.Name ==gpName);//Select it under Toolboxes
projectWindow.SelectItemAsync(toolbox,true,true,null);//null selects it in the first container - optionally await//Note: Project.Current.GetProjectItemContainer("GP") would get toolbox container...//assume toolbox is also under Folders container. Select it under Folders instead of ToolboxesvarfoldersContainer= Project.Current.ProjectItemContainers.First(c => c.Path =="FolderConnection");//We must specify the container because Folders comes second (after Toolboxes)
projectWindow.SelectItemAsync(toolbox,true,true, foldersContainer);//optionally await//Find a map and select itvarmapItem= Project.Current.GetItems<MapProjectItem>().FirstOrDefault(m => m.Name =="Map");//Map only occurs under "Maps" so the container need not be specified
projectWindow.SelectItemAsync(mapItem,true,false,null);
Geodatabase Content
Geodatabase Content from Browse Dialog
varopenDlg=new OpenItemDialog
{Title="Select a Feature Class",InitialLocation=@"C:\Data",MultiSelect=false,BrowseFilter= BrowseProjectFilter.GetFilter(ArcGIS.Desktop.Catalog.ItemFilters.GeodatabaseItems_All)};//show the browse dialogbool?ok= openDlg.ShowDialog();if(!ok.HasValue || openDlg.Items.Count()==0)return;//nothing selectedawait QueuedTask.Run(()=>{// get the itemvaritem= openDlg.Items.First();// see if the item has a datasetif(ItemFactory.Instance.CanGetDataset(item)){// get itusing(vards= ItemFactory.Instance.GetDataset(item)){// access some propertiesvarname= ds.GetName();varpath= ds.GetPath();// if it's a featureclassif(ds is ArcGIS.Core.Data.FeatureClass fc){// create a layer varfeatureLayerParams=new FeatureLayerCreationParams(fc){MapMemberIndex=0};varlayer= LayerFactory.Instance.CreateLayer<FeatureLayer>(featureLayerParams, MapView.Active.Map);// continue}}}});
Geodatabase Content from Catalog selection
// subscribe to event
ProjectWindowSelectedItemsChangedEvent.Subscribe(async(ProjectWindowSelectedItemsChangedEventArgsargs)=>{if(args.IProjectWindow.SelectionCount >0){// get the first selected itemvarselectedItem= args.IProjectWindow.SelectedItems.First();await QueuedTask.Run(()=>{// datasetTypevardataType= ItemFactory.Instance.GetDatasetType(selectedItem);// get the dataset Definitionif(ItemFactory.Instance.CanGetDefinition(selectedItem)){using(vardef= ItemFactory.Instance.GetDefinition(selectedItem)){if(def is ArcGIS.Core.Data.FeatureClassDefinition fcDef){varoidField= fcDef.GetObjectIDField();varshapeField= fcDef.GetShapeField();varshapeType= fcDef.GetShapeType();}elseif(def is ArcGIS.Core.Data.Parcels.ParcelFabricDefinition pfDef){stringver= pfDef.GetSchemaVersion();boolenabled= pfDef.GetTopologyEnabled();}// etc}}// get the datasetif(ItemFactory.Instance.CanGetDataset(selectedItem)){using(vards= ItemFactory.Instance.GetDataset(selectedItem)){if(ds is ArcGIS.Core.Data.FeatureDataset fds){// open featureclasses within the feature dataset// var fcPoint = fds.OpenDataset<FeatureClass>("Point");// var fcPolyline = fds.OpenDataset<FeatureClass>("Polyline");}elseif(ds is FeatureClass fc){varname= fc.GetName()+"_copy";// createvarfeatureLayerParams=new FeatureLayerCreationParams(fc){Name=name,MapMemberIndex=0}; LayerFactory.Instance.CreateLayer<FeatureLayer>(featureLayerParams, MapView.Active.Map);}elseif(ds is Table table){varname= table.GetName()+"_copy";vartableParams=new StandaloneTableCreationParams(table){Name=name};// create StandaloneTableFactory.Instance.CreateStandaloneTable(tableParams, MapView.Active.Map);}}}});}});
Favorites
Add a Favorite - Folder
varitemFolder= ItemFactory.Instance.Create(@"d:\data");// is the folder item already a favorite?varfav= FavoritesManager.Current.GetFavorite(itemFolder);if(fav==null){if(FavoritesManager.Current.CanAddAsFavorite(itemFolder)){fav= FavoritesManager.Current.AddFavorite(itemFolder);}}
Insert a Favorite - Geodatabase path
stringgdbPath="@C:\\myDataFolder\\myData.gdb";varitemGDB= ItemFactory.Instance.Create(gdbPath);// is the item already a favorite?varfav= FavoritesManager.Current.GetFavorite(itemGDB);// no; add it with IsAddedToAllNewProjects set to trueif(fav!=null){if(FavoritesManager.Current.CanAddAsFavorite(itemGDB))
FavoritesManager.Current.InsertFavorite(itemGDB,1,true);}
Add a Favorite - Style project item
StyleProjectItemstyleItem= Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(style =>(style.Name =="ArcGIS 3D"));if(FavoritesManager.Current.CanAddAsFavorite(styleItem)){// add to favorites with IsAddedToAllNewProjects set to false
FavoritesManager.Current.AddFavorite(styleItem);}
Toggle the flag IsAddedToAllNewProjects for a favorite
varitemFolder= ItemFactory.Instance.Create(@"d:\data");// is the folder item already a favorite?varfav= FavoritesManager.Current.GetFavorite(itemFolder);if(fav!=null){if(fav.IsAddedToAllNewProjects)
FavoritesManager.Current.ClearIsAddedToAllNewProjects(fav.Item);else
FavoritesManager.Current.SetIsAddedToAllNewProjects(fav.Item);}
Get the set of favorites and iterate
varfavorites= FavoritesManager.Current.GetFavorites();foreach(var favorite in favorites){boolisAddedToAllProjects= favorite.IsAddedToAllNewProjects;// retrieve the underlying item of the favoriteItemitem= favorite.Item;// Item propertiesvaritemType= item.TypeID;varpath= item.Path;// if it's a folder itemif(item is FolderConnectionProjectItem){}// if it's a goedatabase itemelseif(item is GDBProjectItem){}// else }
Remove All Favorites
varfavorites= FavoritesManager.Current.GetFavorites();foreach(var favorite in favorites)
FavoritesManager.Current.RemoveFavorite(favorite.Item);
FavoritesChangedEvent
ArcGIS.Desktop.Core.Events.FavoritesChangedEvent.Subscribe((args)=>{// favorites have changedintcount= FavoritesManager.Current.GetFavorites().Count;});
Metadata
Item: Get its IMetadata interface
ItemgdbItem= ItemFactory.Instance.Create(@"C:\projectAlpha\GDBs\regionFive.gdb");IMetadatagdbMetadataItem= gdbItem as IMetadata;
Item: Get an item's metadata: GetXML
stringgdbXMLMetadataXmlAsString=string.Empty;gdbXMLMetadataXmlAsString=await QueuedTask.Run(()=> gdbMetadataItem.GetXml());//check metadata was returnedif(!string.IsNullOrEmpty(gdbXMLMetadataXmlAsString)){//use the metadata}
Item: Set the metadata of an item: SetXML
await QueuedTask.Run(()=>{varxml= System.IO.File.ReadAllText(@"E:\Data\Metadata\MetadataForFeatClass.xml");//Will throw InvalidOperationException if the metadata cannot be changed//so check "CanEdit" firstif(featureClassMetadataItem.CanEdit()) featureClassMetadataItem.SetXml(xml);});
Item: Check the metadata can be edited: CanEdit
boolcanEdit1;//Call CanEdit before calling SetXmlawait QueuedTask.Run(()=>canEdit1= metadataItemToCheck.CanEdit());
Item: Updates metadata with the current properties of the item: Synchronize
Item: Delete certain content from the metadata of the current item: DeleteMetadataContent
ItemfeatureClassWithMetadataItem= ItemFactory.Instance.Create(@"C:\projectBeta\GDBs\regionFive.gdb\SourceFeatureClass");//Delete thumbnail content from item's metadataawait QueuedTask.Run(()=> featureClassWithMetadataItem.DeleteMetadataContent(MDDeleteContentOption.esriMDDeleteThumbnail));
Item: Updates metadata with the imported metadata - the input path can be the path to an item with metadata, or a URI to a XML file: ImportMetadata
// the input path can be the path to an item with metadata, or a URI to an XML fileIMetadatametadataItemImport1=null;await QueuedTask.Run(()=> metadataItemImport1.ImportMetadata(@"E:\YellowStone.gdb\MyDataset\MyFeatureClass", MDImportExportOption.esriCurrentMetadataStyle));
Item: Updates metadata with the imported metadata: ImportMetadata
// the input path can be the path to an item with metadata, or a URI to an XML fileawait QueuedTask.Run(()=> metadataItemImport2.ImportMetadata(@"E:\YellowStone.gdb\MyDataset\MyFeatureClass", MDImportExportOption.esriCustomizedStyleSheet,@"E:\StyleSheets\Import\MyImportStyleSheet.xslt"));
Item: export the metadata of the currently selected item: ExportMetadata
//Must be on the QueuedTask.Run()varunit_formats= Enum.GetValues(typeof(UnitFormatType)).OfType<UnitFormatType>().ToList();
System.Diagnostics.Debug.WriteLine("All available units\r\n");foreach(var unit_format in unit_formats){varunits= DisplayUnitFormats.Instance.GetPredefinedProjectUnitFormats(unit_format);
System.Diagnostics.Debug.WriteLine(unit_format.ToString());foreach(var display_unit_format in units){varline=$"{display_unit_format.DisplayName}, {display_unit_format.UnitCode}";
System.Diagnostics.Debug.WriteLine(line);}
System.Diagnostics.Debug.WriteLine("");}
Get The List of Unit Formats for the Current Project
//Must be on the QueuedTask.Run()varunit_formats= Enum.GetValues(typeof(UnitFormatType)).OfType<UnitFormatType>().ToList();
System.Diagnostics.Debug.WriteLine("Project units\r\n");foreach(var unit_format in unit_formats){varunits= DisplayUnitFormats.Instance.GetProjectUnitFormats(unit_format);
System.Diagnostics.Debug.WriteLine(unit_format.ToString());foreach(var display_unit_format in units){varline=$"{display_unit_format.DisplayName}, {display_unit_format.UnitCode}";
System.Diagnostics.Debug.WriteLine(line);}
System.Diagnostics.Debug.WriteLine("");}
Get A Specific List of Unit Formats for the Current Project
//Must be on the QueuedTask.Run()//UnitFormatType.Angular, UnitFormatType.Area, UnitFormatType.Distance, //UnitFormatType.Direction, UnitFormatType.Location, UnitFormatType.Page//UnitFormatType.Symbol2D, UnitFormatType.Symbol3Dvarunits= DisplayUnitFormats.Instance.GetProjectUnitFormats(UnitFormatType.Distance);
Get The List of Default Formats for the Current Project
//Must be on the QueuedTask.Run()varunit_formats= Enum.GetValues(typeof(UnitFormatType)).OfType<UnitFormatType>().ToList();
System.Diagnostics.Debug.WriteLine("Default project units\r\n");foreach(var unit_format in unit_formats){vardefault_unit= DisplayUnitFormats.Instance.GetDefaultProjectUnitFormat(unit_format);varline=$"{unit_format.ToString()}: {default_unit.DisplayName}, {default_unit.UnitCode}";
System.Diagnostics.Debug.WriteLine(line);}
System.Diagnostics.Debug.WriteLine("");
Get A Specific Default Unit Format for the Current Project
//Must be on the QueuedTask.Run()//UnitFormatType.Angular, UnitFormatType.Area, UnitFormatType.Distance, //UnitFormatType.Direction, UnitFormatType.Location, UnitFormatType.Page//UnitFormatType.Symbol2D, UnitFormatType.Symbol3Dvardefault_unit= DisplayUnitFormats.Instance.GetDefaultProjectUnitFormat(
UnitFormatType.Distance);
Set a Specific List of Unit Formats for the Current Project
//Must be on the QueuedTask.Run()//UnitFormatType.Angular, UnitFormatType.Area, UnitFormatType.Distance, //UnitFormatType.Direction, UnitFormatType.Location//Get the full list of all available location unitsvarall_units= DisplayUnitFormats.Instance.GetPredefinedProjectUnitFormats(
UnitFormatType.Location);//keep units with an even factory codevarlist_units= all_units.Where(du => du.UnitCode %2==0).ToList();//set them as the new location unit collection. A new default is not being specified...
DisplayUnitFormats.Instance.SetProjectUnitFormats(list_units);//set them as the new location unit collection along with a new default
DisplayUnitFormats.Instance.SetProjectUnitFormats(
list_units, list_units.First());//Note: UnitFormatType.Page, UnitFormatType.Symbol2D, UnitFormatType.Symbol3D//cannot be set.
Set the Defaults for the Project Unit Formats
//Must be on the QueuedTask.Run()varunit_formats= Enum.GetValues(typeof(UnitFormatType)).OfType<UnitFormatType>().ToList();foreach(var unit_type in unit_formats){varcurrent_default= DisplayUnitFormats.Instance.GetDefaultProjectUnitFormat(unit_type);//Arbitrarily pick the last unit in each unit format listvarreplacement= DisplayUnitFormats.Instance.GetProjectUnitFormats(unit_type).Last();
DisplayUnitFormats.Instance.SetDefaultProjectUnitFormat(replacement);varline=$"{current_default.DisplayName}, {current_default.UnitName}, {current_default.UnitCode}";varline2=$"{replacement.DisplayName}, {replacement.UnitName}, {replacement.UnitCode}";
System.Diagnostics.Debug.WriteLine($"Format: {unit_type.ToString()}");
System.Diagnostics.Debug.WriteLine($" Current default: {line}");
System.Diagnostics.Debug.WriteLine($" Replacement default: {line2}");}
Update Unit Formats for the Project
//UnitFormatType.Angular, UnitFormatType.Area, UnitFormatType.Distance, //UnitFormatType.Direction, UnitFormatType.Locationvarangle_units= DisplayUnitFormats.Instance.GetProjectUnitFormats(UnitFormatType.Angular);//Edit the display name of each unit - append the abbreviationforeach(var unit in angle_units){
unit.DisplayName =$"{unit.DisplayName} ({unit.Abbreviation})";}//apply the changes to the units and set the default to be the first entry
DisplayUnitFormats.Instance.SetProjectUnitFormats(angle_units, angle_units.First());//The project must be saved to persist the changes...
//Set the application to use a custom project, home folder, gdb, and toolbox//In each case, the custom _path_ must be set _first_ before //setting the "option". This ensures the application remains //in a consistent state. This is the same behavior as on the Pro UI.if(string.IsNullOrEmpty(ApplicationOptions.GeneralOptions.StartupProjectPath))
ApplicationOptions.GeneralOptions.StartupProjectPath =@"D:\data\usa.aprx";//custom project path first
ApplicationOptions.GeneralOptions.StartupOption = StartProjectMode.WithDefaultProject;//option to use it secondif(string.IsNullOrEmpty(ApplicationOptions.GeneralOptions.CustomHomeFolder))
ApplicationOptions.GeneralOptions.CustomHomeFolder =@"D:\home_folder";//custom home folder first
ApplicationOptions.GeneralOptions.HomeFolderOption = OptionSetting.UseCustom;//option to use it secondif(string.IsNullOrEmpty(ApplicationOptions.GeneralOptions.CustomDefaultGeodatabase))
ApplicationOptions.GeneralOptions.CustomDefaultGeodatabase =@"D:\data\usa.gdb";//custom gdb path first
ApplicationOptions.GeneralOptions.DefaultGeodatabaseOption = OptionSetting.UseCustom;//option to use it secondif(string.IsNullOrEmpty(ApplicationOptions.GeneralOptions.CustomDefaultToolbox))
ApplicationOptions.GeneralOptions.CustomDefaultToolbox =@"D:\data\usa.tbx";//custom toolbox path first
ApplicationOptions.GeneralOptions.DefaultToolboxOption = OptionSetting.UseCustom;//option to use it second
Set GeneralOptions to Use Defaults
//Default options can be set regardless of the value of the "companion"//path (to a project, folder, gdb, toolbox, etc.). The path value is ignored if//the option setting does not use it. This is the same behavior as on the Pro UI.
ApplicationOptions.GeneralOptions.StartupOption = StartProjectMode.ShowStartPage;
ApplicationOptions.GeneralOptions.HomeFolderOption = OptionSetting.UseDefault;
ApplicationOptions.GeneralOptions.DefaultGeodatabaseOption = OptionSetting.UseDefault;
ApplicationOptions.GeneralOptions.DefaultToolboxOption = OptionSetting.UseDefault;//set default option first//path values can (optionally) be set (back) to null if their //"companion" option setting is the default option.if(ApplicationOptions.GeneralOptions.StartupOption != StartProjectMode.WithDefaultProject)
ApplicationOptions.GeneralOptions.StartupProjectPath =null;if(ApplicationOptions.GeneralOptions.HomeFolderOption == OptionSetting.UseDefault)
ApplicationOptions.GeneralOptions.CustomHomeFolder =null;if(ApplicationOptions.GeneralOptions.DefaultGeodatabaseOption == OptionSetting.UseDefault)
ApplicationOptions.GeneralOptions.CustomDefaultGeodatabase =null;if(ApplicationOptions.GeneralOptions.DefaultToolboxOption == OptionSetting.UseDefault)
ApplicationOptions.GeneralOptions.CustomDefaultToolbox =null;
//Options are mutually exclusive.//Setting ApplicationOptions.DownloadOptions.AskForUnpackPPKXLocation = true//supersedes any value in ApplicationOptions.DownloadOptions.UnpackPPKXLocation//and will prompt the user on an unpack. The value of //ApplicationOptions.DownloadOptions.UnpackPPKXLocation will be unaffected//and is ignored. This is the same behavior as on the Pro UI.
ApplicationOptions.DownloadOptions.AskForUnpackPPKXLocation =true;//override location//The default location is typically <My Documents>\ArcGIS\Packages//Setting ApplicationOptions.DownloadOptions.UnpackPPKXLocation to any//location overrides ApplicationOptions.DownloadOptions.AskForUnpackPPKXLocation//and sets it to false. This is the same behavior as on the Pro UI.
ApplicationOptions.DownloadOptions.UnpackPPKXLocation =@"D:\data\for_ppkx";//Or, if ApplicationOptions.DownloadOptions.UnpackPPKXLocation already//contains a valid path, set ApplicationOptions.DownloadOptions.AskForUnpackPPKXLocation//explicitly to false to use the UnpackPPKXLocationif(!string.IsNullOrEmpty(ApplicationOptions.DownloadOptions.UnpackPPKXLocation))
ApplicationOptions.DownloadOptions.AskForUnpackPPKXLocation =false;
Set DownloadOptions for UnpackOther
//UnpackOther settings control unpacking of anything _other than_//a ppkx or aptx. Options are mutually exclusive.//Set ApplicationOptions.DownloadOptions.UnpackOtherLocation explicitly to//toggle ApplicationOptions.DownloadOptions.AskForUnpackOtherLocation and//ApplicationOptions.DownloadOptions.UnpackOtherToProjectLocation to false//Note: default is typically <My Documents>\ArcGIS\Packages, _not_ null.//This is the same behavior as on the Pro UI.
ApplicationOptions.DownloadOptions.UnpackOtherLocation =@"D:\data\for_other";//or...to use a location already stored in UnpackOtherLocation as the//default without changing it, //set ApplicationOptions.DownloadOptions.AskForUnpackOtherLocation and//ApplicationOptions.DownloadOptions.UnpackOtherToProjectLocation to false//explicitly. This is the same behavior as on the Pro UI.if(!string.IsNullOrEmpty(ApplicationOptions.DownloadOptions.UnpackOtherLocation)){
ApplicationOptions.DownloadOptions.AskForUnpackOtherLocation =false;
ApplicationOptions.DownloadOptions.UnpackOtherToProjectLocation =false;}//Setting ApplicationOptions.DownloadOptions.AskForUnpackOtherLocation to//true overrides any UnpackOtherLocation value and sets //ApplicationOptions.DownloadOptions.UnpackOtherToProjectLocation to false.//This is the same behavior as on the Pro UI.
ApplicationOptions.DownloadOptions.AskForUnpackOtherLocation =true;//Setting ApplicationOptions.DownloadOptions.UnpackOtherToProjectLocation to//true overrides any UnpackOtherLocation value and sets //ApplicationOptions.DownloadOptions.AskForUnpackOtherLocation to false.//This is the same behavior as on the Pro UI.
ApplicationOptions.DownloadOptions.UnpackOtherToProjectLocation =false;
Set DownloadOptions for OfflineMaps
//OfflineMaps settings control where map content that is taken//offline is copied to on the local machine. Options are mutually exclusive.//Set ApplicationOptions.DownloadOptions.OfflineMapsLocation explicitly to//toggle ApplicationOptions.DownloadOptions.AskForOfflineMapsLocation and//ApplicationOptions.DownloadOptions.OfflineMapsToProjectLocation to false//Note: default is typically <My Documents>\ArcGIS\OfflineMaps, _not_ null.//This is the same behavior as on the Pro UI.
ApplicationOptions.DownloadOptions.OfflineMapsLocation =@"D:\data\for_offline";//or...to use a location already stored in OfflineMapsLocation as the//default without changing it, //set ApplicationOptions.DownloadOptions.AskForOfflineMapsLocation and//ApplicationOptions.DownloadOptions.OfflineMapsToProjectLocation to false//explicitly.if(!string.IsNullOrEmpty(ApplicationOptions.DownloadOptions.OfflineMapsLocation)){
ApplicationOptions.DownloadOptions.AskForOfflineMapsLocation =false;
ApplicationOptions.DownloadOptions.OfflineMapsToProjectLocation =false;}//Setting ApplicationOptions.DownloadOptions.AskForOfflineMapsLocation to//true overrides any OfflineMapsLocation value and sets //ApplicationOptions.DownloadOptions.OfflineMapsToProjectLocation to false.//This is the same behavior as on the Pro UI.
ApplicationOptions.DownloadOptions.AskForOfflineMapsLocation =true;//Setting ApplicationOptions.DownloadOptions.OfflineMapsToProjectLocation to//true overrides any OfflineMapsLocation value and sets //ApplicationOptions.DownloadOptions.AskForOfflineMapsLocation to false.//This is the same behavior as on the Pro UI.
ApplicationOptions.DownloadOptions.OfflineMapsToProjectLocation =true;
Portal Project Options
// access the current optionsvardef_home= ApplicationOptions.GeneralOptions.PortalProjectCustomHomeFolder;vardef_gdb= ApplicationOptions.GeneralOptions.PortalProjectCustomDefaultGeodatabase;vardef_tbx= ApplicationOptions.GeneralOptions.PortalProjectCustomDefaultToolbox;vardeleteOnClose= ApplicationOptions.GeneralOptions.PortalProjectDeleteLocalCopyOnClose;vardef_location= ApplicationOptions.GeneralOptions.PortalProjectDownloadLocation;// set the options
ApplicationOptions.GeneralOptions.PortalProjectCustomHomeFolder =@"E:\data";
ApplicationOptions.GeneralOptions.PortalProjectCustomDefaultGeodatabase =@"E:\data\usa.gdb";
ApplicationOptions.GeneralOptions.PortalProjectCustomDefaultToolbox =@"E:\data\usa.tbx";
ApplicationOptions.GeneralOptions.PortalProjectDeleteLocalCopyOnClose =false;
ApplicationOptions.GeneralOptions.PortalProjectDownloadLocation =@"E:\data";