2

I am trying to search a document library for a specific document. I am fairly new to sharepoint and cannot figure out how to retrieve the document.

Below is my code:

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(); } } } } 

1 Answer 1

2

Try this

 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(); } } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.