Click here to Skip to main content
15,898,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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;
        }
    }

}
Posted
Comments
[no name] 4-Feb-12 10:11am    
Try adding some logging. It would be a good idea anyway to log a message to the ULS when/if this time job failed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900