1

I'm create a timer job in sharepoint and have made it quite far. I am running into the issue of having a "this" object in a static method. Here is my code. If anyone has any suggestions, that would be great.

  public static SPListItemCollection GetRecordwithMissingData (string DocType, string DocName)
    {
     //Access associate ID and Doc Name

        //SPWeb web = properties.Feature.Parent as SPWeb;


       SPWebApplication webapp = this.Parent as SPWebApplication;
       SPSite hrdocsSite = webapp.Sites["sites/HRDOCS/HRDocuments"];
       SPWeb rootweb = hrdocsSite.RootWeb;
       SPList AssociateDocumentsList = rootweb.Lists["Associate Documents"];
       SPListItemCollection AssociateDocuments = AssociateDocumentsList.GetItems("ID", "PrimaryName", "DocName", "Document Type");
       // stores Associate Documents ^
user2487016
  • 51
  • 1
  • 3

1 Answers1

0

You cannot have "this" in a static method. There is no instance of what "this" is because it refers to the current instance. One way to fix the problem is to pass an extra parameter to pass an instance of the object you are trying to access the property from. The other option is to have a static instance of whatever type "this" is in the class so the method can access it.

duckbrain
  • 1,219
  • 1
  • 13
  • 26