Hello, I'm reading a text file to populate a combo box so that its items can be easily modified. Which is the default location for such a file if for example I use: new System.IO.StreamReader("myaddin.txt"); ? I've tried putting the text file in the same folder where the myaddin.esriAddInX is (which would be my preferred location) with no success. Where can I have an explanation on what is the process that add-ins go through to search for a file?
Assuming that you want to deploy your file with the Addin archive (and not separately) you can find details here:
In brief, you set the "Copy to Output Directory" property on the text file to "Copy Always" and read the file from the assembly cache. There is code in the ProGuide showing you what to do.
However, in your case, that is probably overkill. Given your content is text I would add the "myaddin.txt" as a Resource to your solution:
Now, in your code you can access the file content directly off the resource class like so:
var file_content = Resource1.myaddin;
Thank you Charles, but neither is what I'm looking for. I want the text file to be external to the Addin so that the lines (each line is an item) can be edited (customized) by each Addin user. The users won't have Visual Studio to access and edit any embedded resource. The "Access Content" link you sent me has a similar concept to what I want which is to get the path where the Addin is located in run time that would then be useful to access the Addin accompanying text file. However it is reading the assembly path and not the actual location of the distributed Addin.
If you need to know the location of an external file it is best to have users install the file to a well-known location (well-known to your Add-in). DotNet has a special enumeration for a series of "special folders" the System.Environment.SpecialFolder Enumeration that can be resolved on any machine. Users copy your file to a particular "special" location (eg My Documents) within which your Add-in always looks for the file. If you desire something more sophisticated, then an installer is required. An installer copies the file to a folder location of the user's choice and records the location in a registry key which your Add-in accesses. The installer would also install your Add-in. This is a very common pattern for file deployment and discovery. Visual Studio has a project template for creating installers called "Setup and Deployment". You'll find it under "Other Project Types".