You'll have to forgive my ignorance with regards to this code. I have written some code to modify an event receiver. I have set up a development environment for SharePoint and finally got it to access and change certain elements of the code.
However, it is the following line where it fails:
Word.Application wordApp = new Word.Application();
In that, it doesn't seem to be able to open the local word application installed on the Sharepoint server in order to process the uploaded document. Any tips on how I would be able to enable the starting of the word application in the SharePoint environment as an event receiver.
The full code is provided below for the sake of completeness
using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;
using Word = Microsoft.Office.Interop.Word;
namespace chrisclementen.chrisclementen
{
public class chrisclementen : SPItemEventReceiver
{
/// <summary>
/// An item was added.
/// </summary>
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
commentscheck(properties);
}
private void commentscheck(SPItemEventProperties properties)
{
bool commentsorrevisions = false;
SPListItem item = properties.ListItem;
SPFile file = item.File;
if (properties.AfterUrl.EndsWith("docx"))
{
commentsorrevisions = WordCommentsChecker(file, properties);
}
}
private static bool WordCommentsChecker(SPFile file, SPItemEventProperties properties)
{
bool outcome = false;
Word.Application wordApp = new Word.Application();
properties.ListItem["Title"] = "bextor";
properties.ListItem.Update();
Word.Document document = wordApp.Documents.Open(file);
int commentscount = document.Comments.Count;
int revisionscount = document.Revisions.Count;
if (commentscount != 0 || revisionscount != 0)
{
Console.WriteLine("comments");
document.ActiveWindow.Close();
wordApp.Application.Quit(-1);
outcome = true;
}
else
{
Console.WriteLine("No Comments.");
document.ActiveWindow.Close();
wordApp.Application.Quit(-1);
outcome = false;
}
return outcome;
}
/// <summary>
/// An item was updated.
/// </summary>
public override void ItemUpdated(SPItemEventProperties properties)
{
commentscheck(properties);
}
}
}