Question

I have an SPJobDefinition (WSS) that runs each hour. Based on some values, and if met, it adds an item to the calendar list. This calendar list has an event receiver attached to the ItemAdded event.

When the job does trigger and adds the item, parts of the code executes. What I mean is that it wont' write to the eventlog and it seems to have problems reading from the web.config file.

If I manually add an item to the calendar list, using my credentials, everything works fine. That is, I have events in the eventlog and the items are read from the web.config file.

I can see where System Account is adding the item in the Calendar list. I've tried adding System Account to the groups with full control and I'm still having a problem.

Is there something else I have to look at to get this to work? I've checked the pool user and it's Network Service; I've since added them to the group as well.

I'm not sure where else to look.

Thanks

Updated (this is the code I use to write to the eventlog)

try
{
  System.Security.Principal.WindowsImpersonationContext wic = System.Security.Principal.WindowsIdentity.Impersonate(IntPtr.Zero);
  EventLog.WriteEntry(source, message, type);
  wic.Undo();
}
catch (Exception)
{
}
Was it helpful?

Solution

Writing to the eventlog could be due to missing windows permissions.

The timer job runs in a windows service which doesn't have a web.config. An event receiver runs in whatever process causing the event. So if you try to read the web.config of the current process it'll fail.

If you try to reach out into the file system to read the web.config, then it might be windows permissions again.

Adding users to SharePoint groups can't help you with access to EventLog or files, these are windows objects not SharePoint objects.

When running from a Timer Job the Impersonate(IntPtr.Zero); isn't changing anything. It impersonates the process account which is already the one running.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top