How to store Add-In settings

How to store Add-In settings

martin_mmj
Enthusiast Enthusiast
1,343 Views
9 Replies
Message 1 of 10

How to store Add-In settings

martin_mmj
Enthusiast
Enthusiast

My Inventor Add-In .dll was created in VisualStudio2008. One of my form is called Add-In Settings. I want to store some settings in .config file but without success.

I use for example:
My.Settings.settingLogsServerName = Me.txtLogsServerName.Text
My.Settings.settingLogsDatabaseName = Me.txtLogsDatabaseName.Text
My.Settings.Save()


After installation my Add-In works fine, but when user changes the settings (by settings dialog) the changes are not stored. How to store user settings for Inventor Add-In? What is the best way?

 

Thanks Martin

0 Likes
1,344 Views
9 Replies
Replies (9)
Message 2 of 10

Mike.Wohletz
Collaborator
Collaborator

What you have should work fine, have you tried to put this in a try catch and have the user try it and see what the error is?

 

 Try
            My.Settings.settingLogsServerName = Me.txtLogsServerName.Text
            My.Settings.settingLogsDatabaseName = Me.txtLogsDatabaseName.Text
            My.Settings.Save()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

 

0 Likes
Message 3 of 10

Anonymous
Not applicable

What O/S did you install it onto?  If it's Vista or 7, then you normally can't write to the Program Files directory.

 

Here's some info on this:
http://www.symantec.com/connect/articles/folder-virtualization-concepts-windows-vista

0 Likes
Message 4 of 10

Mike.Wohletz
Collaborator
Collaborator

Unless you know of another way to make the MY.SETTINGS stored in another place they are normally all going to be stored in %APPDATA%\roaming. You will see a folder with the company or build name and the user.config with the settings are all stored in folders named the same as the application version.Vista and 7 should have no problems working in this location.

 

0 Likes
Message 5 of 10

martin_mmj
Enthusiast
Enthusiast

Hi All. Thanks for your replies.


My Add-In is installed on Windows7_Professional/64bit/CzechLng.
I added "Try-Catch-EndTry" to my code but without errors.

Interesting information for you - I used Sysinternals Process Monitor to detect location of my user.config file. Sorry for very long link :
C:\Users\_MyUserName_\AppData\Local\Autodesk,_Inc\DefaultDomain_Path_irpl5dlpopogzbuk20wxsm2n23hwnsjc\Autodesk®_Inventor®_2010

In my opinion user.config is stored only to temporary location. Question is the same = How to store Add-In settings?

0 Likes
Message 6 of 10

Anonymous
Not applicable

I am not sure what you mean that it is used for Temperary storage.  I use it all the time for my addins and as far as I know it has never gone away.

0 Likes
Message 7 of 10

martin_mmj
Enthusiast
Enthusiast

I thought "....\DefaultDomain_Path_irpl5dlpopogzbuk20wxsm2n23hwnsjc\....." is only some temporary name, but I'm not sure.

In this time I re-wrote my Add-In to store my own XML config file in 'SpecialFolder.ApplicationData' folder of Win7. I think that it will be better.

0 Likes
Message 8 of 10

AlexFielder
Advisor
Advisor

Hi Martin, I don't suppose you'd be willing to share the code snippet that shows how you accomplished writing to/reading from the XML config file? This is something I've been wanting to do for some time, but haven't a clue where to start.

 

Thanks,

 

Alex.

0 Likes
Message 9 of 10

martin_mmj
Enthusiast
Enthusiast

Hi Alex.

I used very very old code to store my own XML settings. I don't know who is author of this class but if you want to do it the same way please see code in attached file.

In my point of view for Win7 is better to change path for store XML for example:
  sb.Append(Environment.GetFolderPath(SpecialFolder.ApplicationData))
  sb.Append("\")
  sb.Append(My.Application.Info.AssemblyName & "_config")
because the UserRights of Win System may prohibit to save xml file.

How to use this class is described on first ten rows of AppSettings.vb. I believe that there are many better and more modern ways to store XML but use this class is very simple.

Good luck

Martin

0 Likes
Message 10 of 10

AlexFielder
Advisor
Advisor

Thanks Martin, I'll be sure to give it a try.

0 Likes