Reading from local file

Add-in Express™ Support Service
That's what is more important than anything else

Reading from local file
... trying to load a javascript file 
George Stavrev

Posts: 17
Joined: 2011-06-30

I am trying to add some javascript that will be loaded on all pages. I am having trouble getting it to load from a file included in the project. I am able to follow the existing project and other ideas such as but they only show how to do it if I have the text as a string.

What if I have say sample.js in my project or /Static/sample.js (inside a folder)? I tried using StreamReader but I can't point it to the right place. I know that my path is likely wrong, but how can I optain the path of where my file is? I tried Path.GetFullPath("Static/sample.js") but that leads to my C:/User/Desktop/Static/sample.js or something of that sort which doesn't host my raw file.

Any suggestions? I don't want to host such files online for now.

Thank you,

Posted 24 Jul, 2013 16:46:19 Top
Sergey Grischenko

Add-in Express team

Posts: 7187
Joined: 2004-07-05
Hi George,

To get the path of the add-on assembly you can use the code below:

Uri uri = new Uri(this.GetType().Assembly.CodeBase);
string addonDir = Path.GetDirectoryName(uri.LocalPath);
string scriptDir = Path.Combine(addonDir, "Static");
Posted 25 Jul, 2013 05:33:39 Top
George Stavrev

Posts: 17
Joined: 2011-06-30
Thanks Sergey! It worked very well for me.
Posted 29 Jul, 2013 18:23:55 Top