Style files location

4535
3
Jump to solution
02-18-2013 04:31 PM
IlyaSolovyev
New Contributor II
Is there any function or property in ArcObjects (.NET) which resolves paths to style files location? I want to avoid hardcoding strings like "C:\Program Files\ArcGIS\Desktop10.1\Styles". I am using ArcGIS 10.1 SP1.

ArcGIS Help says there are user and system folders:

  • <install drive>:\Program Files\ArcGIS\Desktop10.1\Styles

  • On Windows XP, it is located at <install drive>:\Documents and Settings\<username>\Application Data\ESRI\Desktop10.1\ArcMap

  • On Windows Vista and Windows 7, it is located at <install drive>:\Users\<username>\AppData\Roaming\ESRI\Desktop10.1\ArcMap

1 Solution

Accepted Solutions
IlyaSolovyev
New Contributor II
I found out, that we can use IStyleGalleryStorage to retrieve style files folders.


Example:
IStyleGallery StyleGallery = new StyleGalleryClass(); IStyleGalleryStorage StyleGalleryStorage = StyleGallery as IStyleGalleryStorage;  // This is Program Files styles folder string default = StyleGalleryStorage.DefaultLocation;  // All loaded style files for (int i = 0; i < StyleGalleryStorage.FileCount; i++) {       string fullFilePath = StyleGalleryStorage.get_File(i);       // Now you can get directory       string dir = System.IO.Path.GetDirectoryName(fullFilePath);       if (!string.IsNullOrEmpty(dir) && System.IO.Directory.Exists(dir))       {               // Do smth       } }

View solution in original post

0 Kudos
3 Replies
AlexanderGray
Occasional Contributor III
You can get the styles from the registry.  In 10.0 it is under HKEY_LOCAL_MACHINE\Software\ESRI\Desktop10.0\CoreRuntime\StyleDir.  I assume desktop 10.1 has something very similar. 
The main annoyance of using that method is you would have to update the code every time you changed version... 
You might be better off getting a reference to the ArcMap.exe through .net reflections which gives you the path to the bin directory and work your way back to styles.  Of course if esri changes the location in a future version, that won't work either.
0 Kudos
IlyaSolovyev
New Contributor II
You can get the styles from the registry. In 10.0 it is under HKEY_LOCAL_MACHINE\Software\ESRI\Desktop10.0\CoreRuntime\StyleDir. I assume desktop 10.1 has something very similar.


I use this approach now. Also check user's directory.

The main annoyance of using that method is you would have to update the code every time you changed version...


That is why i dont like my approach.

You might be better off getting a reference to the ArcMap.exe through .net reflections which gives you the path to the bin directory and work your way back to styles. Of course if esri changes the location in a future version, that won't work either.


My application is standalone, it doesn't run in ArcMap.
0 Kudos
IlyaSolovyev
New Contributor II
I found out, that we can use IStyleGalleryStorage to retrieve style files folders.


Example:
IStyleGallery StyleGallery = new StyleGalleryClass(); IStyleGalleryStorage StyleGalleryStorage = StyleGallery as IStyleGalleryStorage;  // This is Program Files styles folder string default = StyleGalleryStorage.DefaultLocation;  // All loaded style files for (int i = 0; i < StyleGalleryStorage.FileCount; i++) {       string fullFilePath = StyleGalleryStorage.get_File(i);       // Now you can get directory       string dir = System.IO.Path.GetDirectoryName(fullFilePath);       if (!string.IsNullOrEmpty(dir) && System.IO.Directory.Exists(dir))       {               // Do smth       } }
0 Kudos