0
Sub lookup()
Dim sptSite As SPSite = New SPSite("https://internalsite/sites/trial")
Dim sptWeb As SPWeb = sptSite.OpenWeb()
Dim sptList As SPList = sptWeb.Lists("TestList")
Dim sptItems As SPListItemCollection = sptList.Items
For Each sptItem As SPListItem In sptItems
Response.Write("<h2>" & SPEncode.HtmlEncode(sptItem("Title").ToString) & "</h2>")
Response.Write("<h2>" & SPEncode.HtmlEncode(sptItem("Date").ToString) & "</h2>")
Response.Write("<h2>" & SPEncode.HtmlEncode(sptItem("UserAssigned").ToString) & "</h2>")
Next
End Sub

This was just working a little while ago. I'm not sure what I changed. It complains about the first Response.Write line. If removed, then it complains about the For Each line. I'm assuming it's through a NRE because it can't find "TestList". However, it exists and was working.

Edit: I believe I can confirm it's not finding my custom list anymore.

Sub lookup()
Dim sptSite As SPSite = New SPSite("https://internalsite/sites/trial")
Dim sptWeb As SPWeb = sptSite.OpenWeb()
For Each sptList As SPList In sptWeb.Lists
For Each sptItem As SPListItem In sptList.Items
For Each sptField As SPField In sptItem.Fields
If Not sptField.Hidden And Not sptField.CanBeDeleted Then
Response.Write("<h2>" & SPEncode.HtmlEncode(sptField.ToString) & "</h2>")
End If
Next
Next
Next
End Sub

This lists all fields of every list on my SP server. I cannot find (by CTRL+F) any columns with my custom list's name. I created a new test list, and I can't find that one.

0
Sub lookup()
Dim sptSite As SPSite = New SPSite("https://internalsite/sites/trial")
Dim sptWeb As SPWeb = sptSite.OpenWeb()
For Each sptList As SPList In sptWeb.Lists
If sptList.Title.ToString = "Test" Then
For Each sptItem As SPListItem In sptList.Items
Response.Write("<h2>" & SPEncode.HtmlEncode(sptItem("Title").ToString) & "</h2>")
Next
End If
Next
End Sub

I decided to print out all the List names, and found my custom list. I then decided to use If/Else to find my list, and it worked again. Removing it would result in an exception. Ironically, I was just told our SP server was going to be updated and that was right when I had the issue. Before the update (and the server went down for a bit), I had no troubles. Perhaps the update did something.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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