如何在C#中显示来自Sharepoint列表的项目标题

时间:2019-01-29 01:32:38

标签: c# sharepoint

这是我的功能,但是我可以弄清楚如何在列表框中专门显示项目标题。

private void button1_Click(object sender, EventArgs e)
{
  using (ClientContext ctx = new ClientContext("myurl"))
  {
    ctx.Credentials = CredentialsFactory.SharePointCredentials.CreateCredentials(txtUsername.Text, txtPassword.Text, CredentialsFactory.SharePointCredentials.SharePointAuthentication.SharePointOnline);
    List clinicsList = ctx.Web.Lists.GetByTitle("Clinics");
    CamlQuery query = CamlQuery.CreateAllItemsQuery(1000);
    ListItemCollection clinics = clinicsList.GetItems(query);
    ctx.Load(clinics);
    ctx.ExecuteQuery();
    listBox1.DataSource = clinics.ToList();
  }
}

我确定这真的很简单!预先感谢!

这是输出的屏幕截图。

enter image description here

1 个答案:

答案 0 :(得分:0)

您需要ListItem中的ListItemCollection

// Show item in text box
ListItemCollection clinics = clinicsList.GetItems(query);
 foreach (ListItem item in clinics)
  {
  ListBox1.Items.Add(item.Title);
  }

希望这对您有帮助