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.