Bingjie Han Bingjie Han - 1 year ago 120
C# Question

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

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:
, 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.

Answer Source

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 , "");
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download