title: sharepoint event receiver security exception
body: <p>I have a SharePoint 2010 event receiver that listens for add/update/delete events on a SharePoint list.  When an event occurs the event receiver written in C# needs to pass these events to a Java program.  My code is posted below.  I can deploy the receiver fine and it works.  I get all the SharePoint events I need.  Now my problem is passing these events to Java.  I get security exceptions every time I try to open a socket or write out SharePoint events to a file.  For example, look at the ItemDeleting method I posted below that fires every time an item is deleted from a SharePoint list.  When I try to open a socket to Java I get System.Net.DnsPermission exception.  If I don't open a socket and try to write to a file instead, I get a System.Security.Permissions.FileIOPermission exception.</p>
  
  <p>I looked around the forums and I tried a couple of things to troubleshoot it.  First, I set trust level="Full" in web.xml of SharePoint.  Then I set the DeploymentTarget="GlobalAssemblyCache" of my assembly.  This doesn't help.  What else can I do?  Thank you in advance for your responses.</p>
  
  <p>My event receiver code:</p>
  
  <pre><code>using System;
  using System.Security.Permissions;
  using Microsoft.SharePoint;
  using Microsoft.SharePoint.Security;
  using Microsoft.SharePoint.Utilities;
  using Microsoft.SharePoint.Workflow;
  using System.Net.Sockets;
  using System.IO;
  
  namespace EventReceiverTest
  {
  
      public class EventReceiver1 : SPItemEventReceiver
      {
  
         public override void ItemAdding(SPItemEventProperties properties)
         {
             base.ItemAdding(properties);
         }
  
         public override void ItemUpdating(SPItemEventProperties properties)
         {
             base.ItemUpdating(properties);
         }
  
         public override void ItemDeleting(SPItemEventProperties properties)
         {
             //can't open a socket connection.Request for the permission of type 'System.Net.DnsPermission,... failed
             TcpClient tc = new TcpClient("192.168.xxx.xxx", xxx);
             Console.WriteLine("Server invoked");
             NetworkStream ns = tc.GetStream();
             StreamWriter sw = new StreamWriter(ns);
             sw.WriteLine("item deleted");
             sw.Flush();
             StreamReader sr = new StreamReader(ns);
             Console.WriteLine(sr.ReadLine());
  
  
             //can't write to file.  Request for the permission of type 'System.Security.Permissions.FileIOPermission,...failed
             System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\logs\\test.txt");
             file.WriteLine("item deleted " + properties.ListItem);
  
             //can't output anything to a console
             Console.Out.WriteLine("deleting an item ");
  
             base.ItemDeleting(properties);
  
             //but this part works
             properties.Status = SPEventReceiverStatus.CancelWithError;
             properties.ErrorMessage = "Deleting items from " + properties.RelativeWebUrl + " is not supported.";
         }
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;Feature xmlns="http://schemas.microsoft.com/sharepoint/"&gt;
    &lt;Properties&gt;
      &lt;Property Key="GloballyAvailable" Value="true" /&gt;
    &lt;/Properties&gt;
  &lt;/Feature&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Solution xmlns="http://schemas.microsoft.com/sharepoint/"&gt;
    &lt;Assemblies&gt;
      &lt;Assembly Location="EventReceiver3.dll" DeploymentTarget="GlobalAssemblyCache" /&gt;
    &lt;/Assemblies&gt;
    &lt;FeatureManifests&gt;
      &lt;FeatureManifest Location="EventReceiver3_Feature1\Feature.xml" /&gt;
    &lt;/FeatureManifests&gt;
  &lt;/Solution&gt;
  </code></pre>