25

I'm writing a VSTO Outlook add in and i need to save some settings the addin gets from a web service. What is the best way to do this. Registry? does the VSTO addin have full access to do something like that? Maybe a file containing the settings?

Thanks in advance.

Dan C.
  • 559
  • 3
  • 8
  • 26
  • You need the outlook storage item. I found this video to be very helpful: [How Do I: Use the Outlook Storage Item to Store Add-In Data?](https://web.archive.org/web/20111009034912/http://msdn.microsoft.com/en-us/office/cc837040) – malt_man Dec 14 '11 at 04:43

2 Answers2

31

You can use a Settings (.settings) file.

The advantage of this file, besides having a centralized and strongly-typed repository, is that you can make these settings either application-scoped or user-scoped. Application settings will be available to all users of the computer. User settings will be individualized for each user. (I believe the framework will actually store these settings in separate files somewhere in the OS. I'm not sure, but it doesn't matter. The beauty of the Settings file is that it takes care of the actual storage and retrieval for you.)

Keith
  • 20,636
  • 11
  • 84
  • 125
  • Excellent! This looks great. Especially since this will be deployed as a ClickOnce addin not having to use the registry or a file is ideal. – Dan C. Nov 30 '11 at 21:29
  • 1
    I don't believe this is completely correct, in the link you provided it says these settings are saved to the user.config file. According to [this page](http://blogs.msdn.com/b/rprabhu/archive/2005/06/29/433979.aspx), the user.config file is not supported for VSTO apps. Instead, you'll need to write a custom settings provider. – bmeding Jul 06 '12 at 16:32
  • 1
    @bmeding I can confirm that user- and app-scoped settings do work with VSTO 4. But I assume this wasn't the case with some previous iterations of VSTO since the article you cited is from 2005. – Keith Jul 06 '12 at 18:52
  • 7
    @Keith Using VSTO 4, the user.config is stored in a folder named after the Outlook version number. When the user updates Outlook it will start looking for the user.config file in a different folder (new version number). To the user it will appear as if any of their previous settings have been lost. – bmeding Jul 09 '12 at 19:32
  • So, what is the best way to save data in VSTO projects other than the registry? – Phil Sep 03 '12 at 00:45
  • 2
    @Phil Try the Settings file for Office 2007 and 2010 VSTOs. – Keith Sep 04 '12 at 13:43
  • 3
    Don't add an app.config, use the settings.settings file available in the Project properties. It's true about the settings "appearing to be lost", for enterprise deployments, you'll need to backup the file and restore it as part of your "office upgrade". – Anonymous Type Oct 23 '13 at 22:41
  • Although the user settings work with the default provider in OL 2010, I realized that a regular Office patch (through WSUS server but that doesn't seem too relevant) just hosed the user settings portion. I moved them to the registry now. Since Office is full of COM and highly depends on the registry anyway, making an exception for my puny add in did seem not the best decision. It did add some code lines compared to the settings file however. A custom provider to connect to the registry would be the best solution IMHO. – Roman Gruber May 18 '16 at 19:46
  • 1
    See my answer for details of how to automatically upgrade the settings if the Office version changes, which should resolve the issues discussed here. – Gary McGill Jun 09 '16 at 10:11
  • 1
    Possible location for user.config: C:\Users\\[username]\AppData\Local\Apps\2.0\Data\\[something]\\[something else]\\[based on your VSTO name]\Data\\[outlook version] – John Fouhy Jun 22 '16 at 04:09
7

You can use a Settings file as per @Keith's answer.

There's some discussion in the comments of that answer saying that the settings will be lost if the Office version is upgraded, because the path to the settings file includes the Office version number.

While that's true, there's an easy solution - simply use settings.Upgrade.

Community
  • 1
  • 1
Gary McGill
  • 26,400
  • 25
  • 118
  • 202