Storing XML data for use with an addin

你离开我真会死。 提交于 2019-12-06 09:55:13

问题


I am in the process of creating an outlook addin. The addin works sort of like an aggregator. In this addin, the user will need to specify multiple sets of account information for the addin to have access to...see below:

<Accounts>
  <Account>
    <id>blah1</id>
    <password>blah1 again</password>
  <Account>
  <Account>
    <id>blah2</id>
    <password>blah2 again</password>
  <Account>
  <Account>
    <id>blah3</id>
    <password>blah3 again</password>
  <Account>
</Accounts>

So far I have thought that this should be something simple and light, like an xml data set or some such.

What are my best options for this? If it is an xml file, how do I get to it while I am debugging (i.e. what is the path to the file at both dev and run time). Should I be using the registry (yuck!), should I be looking in a different direction all together?

Thanks!


回答1:


You should create a directory and file per user in the LocalApplicationData folder.

Account Settings Source: C:\Users\\AppData\Local\My Company\account-settings.xml

string userSettingsPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

// build company folder full path
string companyFolder = Path.Combine(userSettingsPath, "My Company");

if (!Directory.Exists(companyFolder)) 
   Directory.CreateDirectory(companyFolder);

// build full settings path
string fullSettingsPath = Path.Combine(companyFolder, "account-settings.xml");

Note: If you need to support roaming user profiles, you should consider using the ApplicationData special folder in place of LocalApplicationData.



来源:https://stackoverflow.com/questions/10019079/storing-xml-data-for-use-with-an-addin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!