-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("mail@site.com", "pass");
                service.TraceEnabled = true;
                service.TraceFlags = TraceFlags.All;
                service.AutodiscoverUrl("mail@site.com", 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 是一项计时器工作。

4

1 回答 1

1

使Pmail.affiche() public.

所以,

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

此外,使用大写命名方法是 C# 约定,所以Affiche()

编辑:

好的,现在我们有了信息,问题是它像我在评论中所说的那样是静态的!

您发布的代码必须有效:

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);
       }
}
于 2013-07-29T09:39:45.947 回答