Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I was not able to do something a little more elaborate with my timer job so I decided to check if something basic works. So I tried the code below - but it keeps giving me this error - why?

UPDATE

Error text is: ArgumentOutOfRangeException was unhandled by user code - Specified argument was out of the range of valid values.

enter image description here

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace AlertAudit
{
public class AlertMailer : SPJobDefinition    {

    public AlertMailer()
        : base() {
    }

    public AlertMailer(string alertName, SPWebApplication webApplication)
        : base(alertName, webApplication, null, SPJobLockType.ContentDatabase)
    {
        this.Title = "Alert Mailerv1";
    }

    public override void Execute(Guid contentDbId)
    {
        base.Execute(contentDbId);
        // get a reference to the current site collection's content database
        SPWebApplication webApplication = this.Parent as SPWebApplication;
        SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId];

        using (SPWeb web = new SPSite("http://myRootSite/").OpenWeb())
        {
            foreach (SPList list in web.Lists)
            {
                Console.WriteLine(list.Title);
            }
        }
    }
}
}

thanks,

KS

share|improve this question
    
is it possible to post the error message directly as text? for some reason the image is not displaying (unsure - it could be blocked at my end). Ta. –  Supriyo SB Chatterjee May 9 '12 at 20:52
3  
Console.WriteLine ?? You are writing timer job not a console application!? –  Vedran Rasol May 9 '12 at 21:23
    
you have mentioned that "it keeps giving me this error".. I can't see it (the error image), so if you could type the error message above within your question itself. –  Supriyo SB Chatterjee May 9 '12 at 21:39
    
thanks for (Update) posting "ArgumentOutOfRangeException" error message. –  Supriyo SB Chatterjee May 10 '12 at 17:22
add comment

1 Answer 1

up vote 0 down vote accepted

First - how can you write to console, if you are running timer job and not a console application?

Second - does your list.Title contain anything that looks like {0}? ArgumentOutOfRangeException at Console.WriteLine would mean, that you didn't give enough parameters to format string. This method works exactly like string.Format():

Console.WriteLine("foo {0}, bar {1)", foo, bar);

If you don't give enough parameters, you get this kind of exception.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.