Hey Everyone!
So i've been experimenting with Sharepoint 2010 and timer jobs. I'm currently trying to upload a file to a document library within a timer job on sharepoint 2010.
For the first part I figured I should try and write to a file first in a sharepoint document library.
I've followed the Microsoft example of making a timer job to add tasks to a task list. This works fine, and uses the web application scope to accomplish this.
My featureactivated and deactivated functions are the same as the link here
http://msdn.microsoft.com/en-us/library/ff798313.aspx[
^] while my exectued function is posted below.
When i check if my job has failed it shows up as succeeded. When i try to debug using the attach ostimer method, I can't seem to hit any breakpoints. I'm hoping for maybe some direction as to how I've gone wrong. I think I dont fully understand the scope and my problem may be to do with this so any helpful thoughts would be appreciated!!!
Thanks
Ethan
public override void Execute(Guid targetInstanceId)
{
using (SPSite spsite1 = new SPSite(siteURL))
{
using (SPWeb spweb = spsite1.OpenWeb())
{
spweb.AllowUnsafeUpdates = true;
SPFolder spfolder = spweb.Folders["CSVUpload"];
byte[] content = null;
using(FileStream filestream = new FileStream("c:\\test\\test\\test.csv", FileMode.Open))
{
content = new byte[(int)filestream.Length];
filestream.Read(content, 0, (int)filestream.Length);
filestream.Close();
}
SPFile spfile = spfolder.Files.Add("test12.csv", content, true);
spweb.AllowUnsafeUpdates=false;
}
}
}