I developed visual web part in SharePoint 2013 to get the SPAudit, when build the solution I get error in the SPAuditQuery

Error 1 The type or namespace name 'SPAuditQuery' could not be found (are you missing a using directive or an assembly reference?)

I already added the using Microsoft.SharePoint;

SPAuditQuery query = new SPAuditQuery(mysiteCollection);

Please help

  • which name space u included in ur code?
    – Waqas Sarwar MVP
    Commented Aug 8, 2017 at 22:07
  • Using Microsoft.SharePoint
    – Habib
    Commented Aug 8, 2017 at 22:29

1 Answer 1


This issue usually occurs because of one of below reasons.

  1. You are not added the Microsoft.SharePoint as a reference to your solution.
  2. You are adding Microsoft.SharePoint as a reference to your solution but not include the name space as using Microsoft.SharePoint;
  3. Your SharePoint solution is Sandbox solution not a Farm Solution


Working with SPAuditEntry via SSOM C# requires a Farm Solution. it will not work with Sandbox solution

Based on what you have mentioned in your quest, you already added the using Microsoft.SharePoint;

So The most likely reason for this problem is using SandBox Solution instead of Farm Solution

To solve your issue, try to switch your solution type to **Farm Solution by doing the following:**

  • In solution explorer, Click on your Project,
  • Click F4 to open the Properties.
  • Set Sandbox solution to false.
  • Rebuild your solution, it should be working.

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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