我正在尝试在文档库中搜索特定文档。我是sharepoint的新手,无法弄清楚如何检索文档。
以下是我的代码:
private void button12_Click(object sender, EventArgs e)
{
using (var site = new SPSite(SiteUrl))
{
if (SiteUrl != null)
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["Documents"];
if (list != null)
{
foreach (SPListItem item in list.Items)
{
if (item.Name.Any() == textBox1.ToString().Any())
listBox1.Items.Add("Document Found");
else
listBox1.Items.Add("Cannot Find Document");
}
web.Close();
}
site.Close();
}
}
}
}
答案 0 :(得分:2)
试试这个
using (var site = new SPSite(SiteUrl))
{
if (SiteUrl != null)
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["Shared Documents"];
if (list != null)
{
int i = 1;
foreach (SPListItem item in list.Items)
{
if (item["Name"].ToString() == TextBox1.Text)
{
Label1.Text = "Document Found";
break;
}
else if (list.Items.Count == i)
{
Label1.Text = "Cannot Find Document";
}
i++;
}
web.Close();
}
site.Close();
}
}
}