Lars Nielsen's Discoveries

January 24, 2012

ArgumentException “Value does not fall within the expected range” error using fields on SPListItem

Filed under: Development,SharePoint,Troubleshooting — Lars Nielsen @ 7:56 pm
Tags: , ,

Here’s a pointer that might save a few minutes (or hours!) of frustration if you hit the same problem as me.  I was trying to extract the column (field) values from an SPListItem.  Easy enough, you just use code like this:


public void ProcessItem(SPListItem item)
{
    string name = item.Name;
    string title = item.Title;
    int id = item.ID;
    // Do something else here
}

OK so far so good. I had this code within my project and ran it. As soon as it got the line where it assigns the name variable it threw an exception:

System.ArgumentException: Value does not fall within the expected range

I put a breakpoint in the function and ran it with the VS debugger attached to the W3WP process to hit the breakpoint.  I began to check the item object in Visual Studio, and tried out a few expressions:

  • item.Name and item.Title both threw the exception
  • item["Name"] and item["Title"] both threw the exception as well
  • item.ID and item["ID"] returned the correct values
  • item.Fields.ContainsField(“Name”), item.Fields.ContainsField(“Title”) and item.Fields.ContainsField(“ID”) returned true
How weird.  The ID column was behaving like I expected, but Title and Name were not.  All three  fields were in the Fields property on the item, but I couldn’t extract their column values without getting the ArgumentException.  It took a while and a fair bit of chasing around on forums to figure this out.  What was happening is that my SPListItem objects were coming out of the results of a query in SharePoint, using an SPQuery object.  It turns out that this is the behaviour you see if you forget to include the columns that you want in the ViewFields property of SPQuery.  This property should have a list of FieldRef XML elements so I had to add elements like this:
<FieldRef Name=’Name’><FieldRef Name=’Title’>
Check the MSDN documentation for more information about using SPQuery and ViewFields.

September 17, 2011

SQL Transaction Logs filling up

Filed under: SharePoint,Troubleshooting — Lars Nielsen @ 7:31 pm

This issue started with someone telling me that they couldn’t update a document in their team site – they got an error saying that they might be a problem with the library or the server might be busy.

I then tried uploading a file to the document library and got an error:

Unable to complete this operation. Please contact your administrator. at Microsoft.SharePoint.Library.SPRequestInternalClass.PutFile(String bstrUrl, String bstrWebRelativeUrl, Object varFile, PutFileOpt PutFileOpt, String bstrCreatedBy, String bstrModifiedBy, Int32 iCreatedByID, Int32 iModifiedByID, Object varTimeCreated, Object varTimeLastModified, Object varProperties, String bstrCheckinComment, UInt32& pdwVirusCheckStatus, String& pVirusCheckMessage) at Microsoft.SharePoint.Library.SPRequest.PutFile(String bstrUrl, String bstrWebRelativeUrl

I then tried updating a list item on the site and got an error:

Exception from HRESULT: 0x80040E14

This was happening not just on this site but on all the parent sites as well, right up to the root of the site collection. Basically it was impossible to do updates on the site collection. I found this page http://fnoja.blogspot.com/2007/12/exception-from-hresult-0x80040e14.html and found plenty of errors in the SQL Server Database server. There was a low space warning on the drive related to transaction logs, and errors in the event log related to the SQL Transaction logs being full. Indeed the LDF files for the content databases were huge because they weren’t being cleared out properly during the backup.  Shrinking down the log files solved the problem. The best way to do this is to is to use DBCC in Server Management Studio – remember to back up the log file first See http://support.microsoft.com/kb/907511. Note that you should not use AutoShrink with SharePoint databases. The moral is: always keep an wary eye on your SharePoint database server…

September 2, 2011

Remove a lock on a file without rebooting

Filed under: Application,Troubleshooting — Lars Nielsen @ 6:51 pm
Tags: , ,

I often used the superb range of tools from SysInternals created by Mark Russinovich.  I first heard about Mark when he exposed the Sony Rootkit copy-protection scandal.  It’s perhaps ironic that Sony, a company that once attempted to infect everyone’s PC with a rootkit to prevent them copying CD’s, should now be the subject of almost weekly security breaches of its own.

Anyway, one of the SysInternals tools I use most is Process Explorer.  This tool is a great way to see what’s going on with the RAM in your system and which processes are most resource-heavy.  One handly use for Process Explorer is when you have a file that’s locked for some reason and you can’t delete or move it.  This can happen, for example, with text files that are not closed properly by an application, or a DLL that’s locked by a service process.  Using Process Explorer, you can search for a file by filename, and it will find all the processes that have a handle onto that file.  If the process is a service, then restarting the service will probably release the lock.  If it’s another process, you might need to kill it to release the lock.  After that you should be able delete, move, or rename  the file in question.

July 26, 2011

Showing recent updates with the Lightning Conductor web part

Filed under: SharePoint — Lars Nielsen @ 10:07 pm

I love using the Lightning Conductor web part.  It’s so flexible and easy to use that it can often replace a data view web part with something easier to configure and that end users can understand.  Does anyone really believe that the Data View Web Part and SharePoint Designer are end user tools?  They’re for developers only in my organisation.  But the Lightning Conductor Web Part is easy enough to understand so end users who understand SharePoint lists, libraries and columns, as well as filtering and sorting, can figure it out.

I recently wanted to configure a LCWP to show the 10 most recently updated documents in a site, across multiple document libraries.  It’s easy enough to configure it to pull data from multiple document libraries.  At first I tried setting the Item Limit in the web part properties pane to be 10, and then sorting the results by Modified date order.  But this failed to pull back some of the more recent documents.

Then I realised this was because the web part was running a query on the site first, but limited to 10 items, and then sorting those 10 results.  I wanted to query all the documents, then sort them and then pick the top 10.  To do this, you leave the Item Limit blank but instead set the Page Size property to be 10 in the web part properties, and uncheck the “Show Page buttons” box.  It’s probably a good idea also to filter the query as well, for example only select documents updated in the last week.  You can do this by setting a condition “greater than or equal” and use the Days Offset setting and set it to Today-7 days.  Otherwise the web part would need to deal with a potentially large result set (and the corresponding SQL traffic in querying across multiple lists) and you may get slow performance as the number of documents in the site grows.

July 7, 2011

Send E-mail to a SharePoint group in SharePoint Designer Workflow

Filed under: SharePoint,Troubleshooting,Development — Lars Nielsen @ 9:00 pm
Tags: ,

When creating a workflow in SharePoint Designer, of course you can use the send e-mail activity to send e-mail notifications to people during the workflow.  The dialog box for the send e-mail activity allows you to choose the recipient of the e-mail. You can either choose individual addresses from the address book, use one of the columns on the workflow item, or choose one of the SharePoint groups associated with the site.

I wanted to use this latter option (mailing a SharePoint group) to notify people when an item in a list had been flagged for deletion.  So I set up a special  group on the site called “Deleted Item Notification”, for people who would get that e-mail.   In my workflow, I set the e-mail activity to send mail to the group  Deleted Item Notification.  I put myself into the  Deleted Item Notification group to test the workflow, flagged an item for deletion and fired off the workflow.  Then I waited for my notification e-mail to arrive.  I waited and waited and.. nothing happened.   I checked the workflow history and it had errored out trying to send the e-mail.

I changed the workflow to e-mail my account directly and it worked fine.  So the problem was sending mail to a group.  It took a while to find a solution to this – the clue was in this post.

I had to change the group settings for the Deleted Item Notification group to allow everyone to see the membership of the group.  I also had to grant that group read access onto the site that was hosting the workflow – I think it would also have worked if I just allowed it to read the list to which my workflow was attached.  After those changes, the workflow sent e-mail correctly.

Next Page »

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.