I'm having a problem to reach a specific SPlist in my sitecollection. The timerjob is supposed to read all items from a SPlist I've choseed and send them to a user through mail. I'm not sure if it's the right location of my site I'm trying to reach. When I'm checking my job history the status of my timerjob says failed and gives me the following errormessage: nativehr 0x80070003 /nativehr nativestack /nativestack. The site im trying to reach has the url: winsharepoint/sites/MLA/AdminSite and the lists name is "Accounting - MLA".
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Utilities;
using System.Collections.Specialized;
using System.IO;
namespace MLATimerjob3
{
public class SimpleJobDefinition : SPJobDefinition
{
public const string JobName = "MLA - Timer job";
public SimpleJobDefinition() : base() { }
public SimpleJobDefinition(SPWebApplication webApp) :
base(JobName, webApp, null, SPJobLockType.Job)
{
Title = "MLA - Timer job";
}
public override void Execute(Guid targetInstanceId)
{
string mailBody = "";
using (SPWeb webSite = new SPSite("http://winsharepoint/sites/MLA/AdminSite").OpenWeb())
{
SPList list = webSite.GetList("Accounting - MLA");
SPSite site = new SPSite("http://winsharepoint/");
SPWeb web = site.OpenWeb("MLA/AdminSite");
foreach (SPListItem item in list.Items)
{
if (DateTime.Parse(item["Serving Date"].ToString()).ToShortDateString()
== DateTime.Now.ToShortDateString())
{
mailBody = item["Menu Item"].ToString() + '\t'
+ item["Specified Meal"].ToString() + '\t'
+ item["Company Name"].ToString() + '\t'
+ item["Price"].ToString() + '\t'
+ item["Guest"].ToString() + '\t'
+ item["Name"].ToString() + '\t'
+ item["Serving Date"].ToString() + '\t'
+ item["Ordered Date"].ToString() + '\n';
}
}
StringDictionary headers = new StringDictionary();
headers.Add("to", "daniel@example.com");
headers.Add("cc", "xyz@abc.com");
headers.Add("bcc", "");
headers.Add("from", "email@add.com");
headers.Add("subject", "Email Subject");
headers.Add("content-type", "text/html");
SPUtility.SendEmail(web, headers, mailBody);
}
}
}
}