Read custom file path from VSTO plugin? - c#

I have an excel plugin where I want to read an xml file on form load from a config folder, but I can't figure out how to read from that folder after I deploy the application.
On the excel ribbon, when the user clicks a button to open my plugin, on form load, I want to read from a specified directory. I am deploying the application with ClickOnce and using VS 2017. I set the xml file build to Content and set Copy to output directory as Always. When I deploy, it puts the xml file in some ClickOnce dll folder when the user installs it.

Try InstallDir = Environment.CurrentDirectory; at startup of you plugin.
In ThisAddIn_Startup or in your ribbon constructor.

Related

c# Excel AddIn, find content file path when excuting

I am using VSTO to build an Excel AddIn. In this project, I also added some python .py scripts to do some data manipualtion.
The whole project is a C# project, all the .py files are taken as content files of the project, in detail, what I did is setting Properities-Build Action as 'Content', setting Properities-Copy to Output Directory as 'Copy always'.
However, after publish with clickonce, when executing, I couldn't find where the content files are. I already tried like: Application.StartupPath, but did't work. I really need to find the content files path and step into them.
Thanks in advance to anyone who take time to see my question.
Publish page of an office add-in project doesn't have an Application Files button which means you can not include some files in the click once installer in the way that you do it for applications. As an option, you can put your files as embedded resources and then at startup of the add-in, extract them from resources and copy them to add-in output directory.
To do so, you can add your file to Resources.resx and then at StartUp of your add-in, extract the file from resources and save it to the deployment directory and use it.
var assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
var assemblyFolder = System.IO.Path.GetDirectoryName(assemblyLocation);
var file = System.IO.Path.Combine(assemblyFolder , "test.py");
if (!System.IO.File.Exists(file))
System.IO.File.WriteAllBytes(file, Properties.Resources.test);
Now the file is in the path specified in file variable.

VSTO Installable or exe

I have created a Excel Add in Application and i have built an .VSTO file out of it.
Now whether i need to create installer for installing it or is there is any we can create .exe file (without installer).
I don't want the installer option as some of the user's will not be having admin access.
So can we create .exe file out of VSTO Excel Add in.
Thanks,
Karthik
If I have understood properly below is the answer....
When do you publish Addin project using right click on project, you can see the *.VSTO file get created on provided path.
That *.vsto file is itself a installer.
In order to "install" an add-in, you require registry entries similar to ours shown below
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\Word\Addins\Chem4Word]
"Description"="Chem4Word"
"FriendlyName"="Chem4Word"
"Manifest"="file:///C:/Dev/Chem4Word/WordAddIn/WordAddIn/bin/Debug/WordAddIn.vsto|vstolocal"
"LoadBehavior"=dword:00000003
Simply change the Manifest location is the location where your .vsto and .dll files are.
Also as this example is for our Word Add-in "Word" also needs to be changed to "Excel" where appropriate.

How do I configure VS installer to put files in LocalApplicationData

Everything in Visual Studio seems to lead one to putting data files with the application.The app.config goes there, when I create an .XML data file, there is a Copy to Output property that will automatically copy that file to the exe folder. Howerver, it seems that under Vista and Win7 UAC doesn't want the application to be able to write data to any file in the application directory. So I'm changing my evil ways so that I use the LocalApplicationData folder for files I want to read and write. (I just read the app.config so I'm leaving it alone)
I'm using a VS2010 Visual Studio Installer project to create the installer for this app and I can't seem to find a way to target the folder for my .xml file to the LocalApplicationData folder. I can click on the file and see a Folder property but the dialog only has options for Application Folder, User's Desktop and User's Program Menu. Is there some way to do this in the installer or do I have to write code that checks for the file and copies it over from the .exe folder when it doesn't exist? I figure I'm late to this particular party and there must be a canonical way of handling this.
Also, I'm wondering about debugging, is there something similar to the copy if newer functionality in the build process that will now copy this .xml file automatically over to the LocalApplicationData folder whenever I update it?
The Setup project doesn't expose LocalApplicationData in the Special Folders list. You can use it anyway by doing this:
Add a Custom Folder and set the DefaultLocation property to [LocalAppDataFolder]

Can WIX modify XML files inside an XAP package?

I am using WIX to automatically modify web.config files depending on the environment the user is installing. I did this using WixUtilExtension and a cutom "choose environment" dialog UI.
I was wondering if there is any possible way to make WIX modify xml files inside a XAP package such as ServiceReferences.ClientConfig file?
A little bit quirky, but most probably you will end up with a custom action that will:
Extract the XAP (as a zip file)
Load the ServiceReferences.ClientConfig from a temp folder
Update the config file with the user inputs
Re-zip it as XAP

Folder and file not added to User's Application Data folder

Ladies and Gentlemen , I have been stuck with this for a few hours and do not find an answer. I have a Setup project in Visual Studio that creates an installer for my C# application. What I want is to add a folder with an XML file from which my application can read and write to the User's Application Data folder. In the File System Editor window I added the User's Application Data folder. In this folder I added a new folder (renaming it to my app's name) and then place the XML file in there. I also set the AlwaysCreate to true for the folder. The installer should create the folder in C:\Users\UserName\AppData\Local and add the file to it. However, the installer does not create the folder or the XML file my application uses. What am I missing? Is there another way to install a read/write XML file? Thanks in advance!
Ok, I found what the issue was. If a file is added to the User's Application Data folder it is installed on the target computer at C:\Users\Username\AppData\Roaming and not into AppData\Local.
Therefore, I changed my application get the file from Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) instead of Environment.GetFolderPath( Environment.SpecialFolder.LocalApplicationData).
Hope it helps someone else...

Categories

Resources