2013-07-29 4 views
-3

문제가메서드가 현재 컨텍스트에 없습니다.

"Affiche()"가 현재 컨텍스트에 없습니다.

클래스 OPPSVotesStatistiques

코드는 다음과 같습니다 :

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.SharePoint.Administration; 
using Microsoft.SharePoint; 
using System.Configuration; 


namespace Components.Jobs 
{ 
    class OPPSVotesStatistiques : SPJobDefinition 
    { 

     private Pmail p; 

     public OPPSVotesStatistiques() 
      : base() 
     { 

     }  
     public OPPSVotesStatistiques(string jobName, SPWebApplication webApplication) 
      : base(jobName, webApplication, null, SPJobLockType.ContentDatabase) 
     { 
      this.Title = "ListLogger"; 

     } 

     public override void Execute(Guid contentDbId) 
     { 
      Pmail p = new Pmail(); 
      InsretListAvis addAvis = new InsretListAvis(); 

      List<AttributMail> listMail = Pmail.Affiche(); 

      foreach (AttributMail m in listMail) 
      { 
       info = addAvis.Insert(m.Projet, m.Phase, m); 
     }}} 


class Pmail 

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.Exchange.WebServices.Data; 
using Microsoft.Exchange.WebServices.Autodiscover; 
using System.Security.Cryptography.X509Certificates; 
using System.Net; 
using System.Text.RegularExpressions; 

namespace Components.MailVote 
{ 
    class Pmail 
    { 

     public Pmail() 
     { 
     } 


     public static List<AttributMail> Affiche() 
     { 
      List<AttributMail> lmail = new List<AttributMail>(); 

      try 
      { 

       ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack; 
       ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); 

       //service.Credentials = new NetworkCredential("{Active Directory ID}", "{Password}", "{Domain Name}"); 
       service.Credentials = new WebCredentials("[email protected]", "pass"); 
       service.TraceEnabled = true; 
       service.TraceFlags = TraceFlags.All; 
       service.AutodiscoverUrl("[email protected]", RedirectionUrlValidationCallback); 

       Folder inbox = Folder.Bind(service, WellKnownFolderName.Inbox); 


       //The search filter to get unread email 

       SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false)); 

       PropertySet itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties); 
       itempropertyset.RequestedBodyType = BodyType.Text; 
       ItemView view = new ItemView(50); 
       view.PropertySet = itempropertyset; 

       //Fire the query for the unread items 

       FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, sf, view); 

       foreach (Item item in findResults.Items) 
       { 
        AttributMail m = new AttributMail(); 
        item.Load(itempropertyset); 
        m.From = (item as EmailMessage).Sender.Name; 
        m.Sujet = item.Subject; 
        m.Txt = item.Body; 
        m.Date = item.DateTimeReceived.TimeOfDay.ToString(); 
        m.Cc = item.DisplayCc; 
        lmail.Add(m); 
      } } 
catch(Exception ex){ 
} 
return lmail;}}} 

이 타이머 작업이 메일을 읽을 및 SPlist에 데이터를 삽입 할 수 있습니다.

+0

그것은'Pmail' 클래스는'affiche'라는 함수를 가지고 있지 않음을 의미한다. 함수가 있으면 public인지 확인하십시오. –

+0

''Pmail'의 정의를 게시하십시오. –

+0

Pmail에 affiche라는 메소드가 있습니까? 그렇다면 사적인 것인가? –

답변

1

제조사 Pmail.affiche()public.은, 지금 우리는 정보를 가지고, 문제는 괜찮

:

그래서, 또한

public class Pmail 
{ 
    public List<AttributMail> affiche() 
    { 
     ... 
    } 
} 

는 그렇게 Affiche()

편집, 대문자와 이름 방법으로 C#을 규칙입니다 그것은 내가 코멘트에서 말했던 것처럼 정적이다!

당신이 게시 한 코드가 작동해야합니다

Pmail.Affiche(); 

Pmail p = new Pmail(); 
p.Affiche(); // will not work as you can't call a static method on an instance. 

그래서

public override void Execute(Guid contentDbId) 
{ 
     InsretListAvis addAvis = new InsretListAvis(); 

     List<AttributMail> listMail = Pmail.Affiche(); // static call 

     foreach (AttributMail m in listMail) 
     { 
      info = addAvis.Insert(m.Projet, m.Phase, m); 
     } 
} 
+0

이것은 Pmail 클래스입니다. – Imen

+0

''affiche''는'정적'입니까? 'C# '의 인스턴스에'static' 메서드를 호출 할 수 없습니다 –

+0

public list affiche() { ... } – Imen

관련 문제