access is denied in sharepoint document library event handler word



am opening wordapplication object (Have a reference to Microsfot Interop
assembly) on the server side in sharepoint document library even handler.

I am getting "access is denied" exception. The user is "SPSUser"
Can somebody please help me to overcome this exception.

My code : (getting expception when creating wordapplicaiton)

void IListEventSink.OnEvent(Microsoft.SharePoint.SPListEvent listEvent)
{
IntPtr tokenHandler =
System.Security.Principal.WindowsIdentity.GetCurrent().Token;
WindowsIdentity objWindowsIdentity = new WindowsIdentity(tokenHandler);
CloseHandle(tokenHandler);

WindowsImpersonationContext objWindowsImpersonationContext =
objWindowsIdentity.Impersonate();

try
{
if (listEvent.Type == SPListEventType.Insert)
{
SPWeb site = listEvent.Site.OpenWeb();
SPFile file = site.GetFile(listEvent.UrlAfter);
string fileName = file.Name;
int length = fileName.Length;
string fileExtension = fileName.Substring(length-3);
if(fileExtension.Equals("doc"))
{
wordApplication = new ApplicationClass();
..
..
.. .
..
.. objWordFormExtract.FileName = file.Url;
objWordFormExtract.LoadMyScenarioRecord(ref objScenarioRecord);
if (objScenarioRecord != null)
{
if(objScenarioRecord.StoreRecordInDataBase())
{ errorMessage = "Document is uploaded successfully"; }
}
else
{ errorMessage = objInfoPathFormExtract.ErrorMessage; }
}
}

}

.



Relevant Pages