3

I am writing a simple VS2012 AddIn and I am not sure where and how I should store data that I need to reuse the next time the AddIn is opened. I was thinking about simply storing the data in an XML file in the same folder as the binary but then I started thinking that there ought to be a smarter way to persist user data in an AddIn, maybe it is common to save it in a system or user folder?

Thus my question is: Is there any best practice on how/where to store data from a VS2012 AddIn?

Any help greatly appreciated.

Marcus
  • 8,230
  • 11
  • 61
  • 88

1 Answers1

2

If the data apply at the whole addin, regardless of the user logged in, I suggest to write your XML file in the folder defined by Environment.SpecialFolder.CommonApplicationData

 string commonPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
 string myAddinDataPath = Path.Combine(commonPath, "MyAddinName");
 if(!Directory.Exists(myAddinDataPath)) Directory.CreateDirectory(myAddinDataPath);

instead, if you have different data based on the current user, write in the the folder defined by Environment.SpecialFolder.ApplicationData

Steve
  • 213,761
  • 22
  • 232
  • 286
  • Nice! That was kind of what I was thinking as a fallback plan but I was looking for a more straightforward "standard" way for AddIns. Do you suggest this over serializing to string and using the EnvDTE Globals interface? Related: http://msdn.microsoft.com/en-us/library/envdte.globals.aspx, http://msdn.microsoft.com/en-us/library/vstudio/96t389k3.aspx – Marcus May 27 '13 at 14:22
  • @Marcus, sorry I haven't enough experience with addins to give advices. Usually I prefer a already made solution if it is available as the manufacturer (Microsoft) of the solution is (morally) obligated to keep it running, but this does not always occur (see Macro in VS2012) – Steve May 27 '13 at 14:29
  • 1
    I agree, I considered Globals in the first place since it is an already made solution for persistance but since it cannot store arrays or objects and requires serialization to work in my case I think it was never meant to persist anything bigger than flags and word long strings. For now, I will implement your solution since it is more generic and easily verifiable, therefor also marking your answer as correct. Thank you for your help! – Marcus May 27 '13 at 14:34