Ok, so I have this code which keeps tossing the error above. I am really pulling my hair out trying to figure it out.
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Collections.Generic;
using System.Collections;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace VarianceList.WebPart1
{
[ToolboxItemAttribute(false)]
public class WebPart1 : WebPart
{
private class ListColumns
{
public String li_requestDate { get; set; }
public String li_paymentAmount { get; set; }
public String li_payeeName { get; set; }
}
Here is where the error starts:
private List<listcolumns> ReadFromList()
{
List<listcolumns> lcList = new List<listcolumns>();
using (SPSite site = new SPSite("http://ServerName"))
{
using (SPWeb web = site.OpenWeb("locationOfWeb"))
{
SPList list = web.Lists["ListName"];
SPListItemCollection SpListColl = list.Items;
foreach (SPListItem item in SpListColl)
{
ListColumns lc = new ListColumns();
if (null != item["Title"])
{
if (!(String.IsNullOrEmpty(item["RequestDate"].ToString())))
{
lc.li_requestDate = item["RequestDate"].ToString();
}
// . . . and so forth
also, right here I am getting the following error: cannot convert from 'VarianceList.WebPart1.WebPart1.ListColumns' to 'listcolumns'
lcList.Add(lc);
}
}
} // using (SPWeb
} // using (SPSite
return lcList;
} }
}
C# is a case-sensitive language. You defined a class
ListColumns
, but you're referring to it aslistcolumns
.That won't work.