我的问题是
当前上下文不存在“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的计时器工作。
答案 0 :(得分: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);
}
}