When we use the app, we will find some problems, such as the site deployment, update or uninstall, we are very concerned about whether our app is used, this requires remote event receiver.
1. Select the mouse on the solution of our test app, press F4 pop-up property, select the processing application we need, check true, and VS will automatically create a solution that lets us write the relevant code for the remote event receiver.
2, in the creation of the remote event receiver solution, open the SVC code, and then add our code (attached), to determine if the event that triggered the installation of the app, in a appinstalllog list to insert an installation record.
3, after the code, the code is very simple, improve the permissions to write the list library, not much to say; after writing the code, publish the Web site to the server's IIS directory;
if (properties. EventType = = spremoteeventtype.appinstalled)
{
spsecurity.runwithelevatedprivileges (delegate ()
{
using (SPSite site = new SPSite ("http://url:2014"))
{
using (SPWeb web = site. OpenWeb ())
{
SPList list = web. lists["Appinstalllogs"];
SPListItem item = list. Items.Add ();
item["title"] = "Sp2013picturewallapp";
item["Log"] = "Sp2013picturewallapp to" + DateTime.Now.ToString () + "has been installed. ";
Item. Update ();}}
);
}
4, in the app solution, find the Appmanifest.xml file, right-click to view the code, modify the Installedeventendpoint as we previously released the site of the Svc file directory;
5, we add our app in a site, and then look at the Appinstalllogs list library, found that an installation log has been written, indicating that the remote event receiver development deployment was successful.
Concluding remarks
The above describes the process of triggering an event to write to the installation log during the app installation process, in fact, remote event receivers can also do a richer job, such as event triggers in a SharePoint solution, add events to a list or document library in an app, which requires us to create remote Event Receiver solution.
Special Recommendations
The idea of the above is referenced from the Microsoft SharePoint app Development book, the simple look at the table of contents, the introduction of APP development is very good, recommend to everyone.