1

我在 sharepoint 中创建了一个计时器作业,并且已经做得很远了。我遇到了在静态方法中有一个“this”对象的问题。这是我的代码。如果有人有任何建议,那就太好了。

  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 ^
4

1 回答 1

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.

于 2013-06-14T17:22:56.337 回答