I have an office Excel add-in written in TypeScript and I need to include a configuration XML file where I could save some settings which should be preserved across all documents. I included the XML file in the task pane folder like this:
Directory of C:\Users\user\add-in\src\taskpane
01/30/2022 06:40 PM <DIR> .
01/30/2022 06:40 PM <DIR> ..
01/29/2022 09:13 PM 259 settings.xml
01/28/2022 07:20 PM 3,639 taskpane.css
01/28/2022 04:31 PM 2,307 taskpane.html
01/30/2022 06:47 PM 24,187 taskpane.ts
I try to read the file using this code:
function readSettings() {
try {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = readSettingsHandler;
xhttp.open("GET", "settings.xml", true);
xhttp.send();
} catch (error) {
console.error(error);
}
}
function readSettingsHandler(event) {
try {
if (this.readyState == 4 && this.status == 0) {
var content = this.responseText;
console.log(content);
}
} catch (error) {
console.error(error);
}
}
I get 404 Not found error. As a test, I tried to specify the full path, like this:
xhttp.open("GET", "C:\\Users\\user\\add-in\\src\\taskpane\\settings.xml", true);
Then the script sees the file, but I get a "blocked:other" error and the responseText property returns an empty string.
What is the correct way to include a settings file in an Office add-in project?