OfficeDev/Office-Add-in-JavaScript-WebApiService

Name: Office-Add-in-JavaScript-WebApiService

Owner: Office Developer

Description: Shows how to create and query an ASP.NET Web API service from an Office Add-in.

Created: 2015-08-12 22:41:04.0

Updated: 2018-04-24 22:52:12.0

Pushed: 2017-12-28 21:31:15.0

Homepage:

Size: 925

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Office Add-in: Create a web service for an Office Add-in using the ASP.NET Web API

Table of contents

Summary

This sample demonstrates how to create and query an ASP.NET Web API service from an Office Add-in. The sample is comprised of a “Send Feedback” page, which lets a user submit feedback, and uses a Web API service to send it to the developer team.

Prerequisites

This sample requires the following:

Key components of the sample

The sample solution contains the following key files:

WebApi Sample project

WebApi SampleWeb project

Description of the code

The Office Add-in makes an AJAX request to the web service, passing in data from the client-side JavaScript code. The Web API controller receives the data, performs an action, and returns the results back to the caller. The AJAX call then completes, displaying the results or showing an error message.

Build and debug

The sample will run right out of the box, but it won't be able to send feedback unless you configure appropriate credentials. To configure the credentials, open SendFeedbackController.cs (in the Controllers folder of the web project) and update the following constants with actual values:

t string MailingAddressFrom = "add-in_name@contoso.com ";
t string MailingAddressTo = "dev_team@contoso.com";
t string SmtpHost = "smtp.contoso.com";
t int SmtpPort = 587;
t bool SmtpEnableSsl = true;
t string SmtpCredentialsUsername = "username";
t string SmtpCredentialsPassword = "password";
  1. Open the solution in Visual Studio.
  2. Press F5 to build and deploy the sample add-in to the client that's specified as the start document (by default, Excel). To change this setting, click the WebApi Sample project in Solution Explorer and select your preferred Office application.
  3. On the Home ribbon, click the Open button in the Web API group.
  4. In the add-in, choose a rating in the drop-down list, enter some feedback, and click Send it! A toast notification opens to tell you whether your feedback was successfully sent.

Troubleshooting

Questions and comments

Additional resources
Copyright

Copyright (c) 2015 Microsoft. All rights reserved.

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.