Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using SharePoint foundation. I have a console application that is used to run some OCR process. I am calling the exe of the console application from windows service and it is working fine. I am trying to call the same exe from an event receiver but unable to call the exe and getting some error. The Event receiver is working fine but unable to call exe. I have tried to call the other exes like notepad.exe but getting same error. The details are below:

Code:

   public override void ItemAdded(SPItemEventProperties properties)
   {

   try
   {
       base.ItemAdded(properties);
       Log("Event Occured.");
       string OCRedText = string.Empty;
       string Listname = properties.ListTitle;
       string itemName = Convert.ToString(properties.ListItem["Name"]);
       string itemTitle = Convert.ToString(properties.ListItem["Title"]);

       callService(); // Here is the method to call Process                

       SPListItem item = properties.ListItem;
       if (System.Threading.Monitor.TryEnter(myLock, TimeSpan.FromSeconds(100)))
       {
           if (Convert.ToString(item["OCRed"]) == "False")
           {                       
               item["OCRed"] = "True";
               Thread.Sleep(10000);
               item.SystemUpdate();
               Log("Item Added and Updated.");
           }
           else
           {
               Log("Can not update the Item.");
           }
       }
       Log("Event End."+"\r\n");
   }
   catch (Exception ex)
   {
       Log("Error in Item Added Event Receiver.");
       Log(ex.ToString());               
   }
}

public void callService()
{
    Log("Calling Service is not easy.");
    try
    {
        ProcessStartInfo pinfoService = new ProcessStartInfo();
        pinfoService.FileName = @"D:\Khan\khan.exe";
        //pinfoService.FileName = @"C:\Windows\System32\notepad.exe";
        pinfoService.UseShellExecute = false;
        pinfoService.RedirectStandardError = true;
        pinfoService.RedirectStandardInput = true;
        pinfoService.RedirectStandardOutput = true;
        pinfoService.CreateNoWindow = true;
        pinfoService.WindowStyle = ProcessWindowStyle.Hidden;
        Log("FileName: " + pinfoService.FileName);
        Log("Arguments for callService : "+pinfoService.Arguments);
        Process pService = new Process();

        pService.StartInfo = pinfoService;
        Log("Process Before Start.");
        Thread.Sleep(5000);
        pService.Start();
        Thread.Sleep(2000);
        Log("Process Before wait for exit.");
        pService.WaitForExit();
        Log("Process Completed.");
    }
    catch (Exception ex)
    {
        Log("Error in callService(). Please contact your Administrator.");
        Log(ex.ToString());
    }
}

and below is the error I am getting on pService.Start();

=========================================

Info : Process Before Start.

Info : Error in callService(). Please contact your Administrator.

Info : System.ComponentModel.Win32Exception: Not enough quota is available to process this command

at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)

at OCRonUploadDoc.EventReceiver1.EventReceiver1.callService()

=========================================

I am unable to figure out the issue. Please help me...!!!

Thanks in Advance.

  • Khan Abubakar
share|improve this question
    
Is that "notepad.exe" starting alright, or does it give same error? I assume you're not trying to use Sandboxed Solution for this? –  Jussi Palo May 10 '12 at 7:59
    
Unable to call notepad.exe using above code. –  MAK May 10 '12 at 9:12

4 Answers 4

up vote 1 down vote accepted

I would highly recommend changing the solution to Farm from sandbox because your code is trying to call external processes on the OS. I believe you can easily do that from project properties in VS.

share|improve this answer
    
Thanks Emon. I have created an another solution "Farm solution" and it is able to call the process. I can do OCR on Item added Event Receiver. BTW I like Suggestion from @Paul Schaeflein so Planning to do the same. Because Event Receiver may get fail to work on Big file OCR. –  MAK May 11 '12 at 11:34

Try changing web.config truest level from "WSS_Minimal" to "Full" to verify it isn't permission related. If "Full" solves your problem, figure out what CAS policy is preventing your code from working and create custom policy for it.

Remember to revert to "WSS_Minimal" after testing this.

share|improve this answer
    
Thanks @Jussi Palo for replying my question. Changed the trust level from "WSS_Minimal" to "Full" but not working. –  MAK May 10 '12 at 9:37
1  
No, no, no. Do not expose yourself to such risk. Ever. –  Paul Schaeflein May 10 '12 at 15:40
    
"Trying with Full" doesn't mean "leave it to Full". Simple troubleshooting steps in scoping where the issue might be. Assemblies in GAC run with "Full" anyway. –  Jussi Palo May 14 '12 at 9:53

Your architecture is completely wrong.

Event receivers are best for short, non-intensive operations. Anything that requires resources, such as loading an exe into a new process, should be performed outside of the event process.

As an example, the event receiver can queue a request that is processed by a service application. This model is how everything works in SharePoint (feature activation, workflows, etc.)

share|improve this answer
    
I agree, this should not be implemented as an event receiver, but an event receiver could be used to trigger the processing somewhere else, say a web service or timer job. –  Daniel Butler May 10 '12 at 22:55
    
Actually I want to do the OCR on document that is added now. So on Item Added Event the OCR should be done and then updating the Library about the document is OCRed or not. I have created Windows Service doing OCR on document in a Local folder and upload the document with OCR data in Library. To do the same on "Add Document" I have to use Item Added event. –  MAK May 11 '12 at 5:05

I assume from the "Not enough quota is available to process this command" you are running this code as a Sandbox solution. You will not be able to execute it this way because of the restrictions of the sandbox.

You can try and increase the quota size by adding resource points, but you will probably run into an access denied error afterwards.

What are you actually trying to do with the console application, are you using it to get around some other limitation?

Have you tried to deploy the solution in the farm solution gallery, so the dll is running from the GAC?

share|improve this answer
    
Thanks Daniel for your response. 1) I am using an event receiver deployed as Sandbox solution. 2) Console Application is used to OCR the file and extract the text from different type of files. 3) It is Sandbox solution so not deployed in farm solution gallery. 4) Dll added in GAC. 5) This is an event receiver and I can log the comments too. but can not start a process. –  MAK May 10 '12 at 12:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.