Search code examples
c#javascriptcomms-officecomvisible

any possibility to call C# function with javascript?


I wrote an office addin and with which there is a function : openFile(String path) and in the office addin I embed a browser object and with that I can embed a webpage on the office addin, and now I hope I can call the C# function "openFile" and pass in a path in the webpage with javascript, and let office open the designated file for me . Is this possible ? What can I do ?


Solution

  • Yes it is possible.

    This is done via the window.external property (and ObjectForScripting on the host side). See WebBrowser Control Overview under the FAQ.

    Happy coding.

    Edit: However, there is likely not a way to access the value supplied to a file upload field unless you use a BHO -- this is a secondary question/issue, if it exists.