I need to make query in SharePoint WebPart with VisualStudio. I have list "Employees" and need to check this list for existing UserName!
<tr>
<td class="auto-style1">User Name<span class="ms-error">*</span></td>
<td>
<asp:TextBox
ID="txtEmpUName"
runat="server">
</asp:TextBox>
<br />
</td>
</tr>
//UserName Validation
if (string.IsNullOrEmpty(txtEmpUName.Text.Trim()))
{
return "Fill the User Name!";
}
using (SPSite oSPsite = new SPSite("http://webapp/sites/siteCollection/"))
{
using (SPWeb oSPWeb = oSPsite.OpenWeb())
{
SPList EmpList = oSPWeb.Lists["Employees"];
for (int i = 0; i < EmpList.Fields.Count; i++)
{
if (EmpList.Fields[i].Title == txtEmpUName.Text)
{
return "UserName exists";
}
}
}
}
How to check for existing Field in ListItem ? Thank you previously!