Skip to main content

Posts

Showing posts with the label loop

Loop through selected nodes of a treeview control

foreach (TreeNode node in tvBusinessUnit.CheckedNodes) { lblSelectedBusinessUnit.Visible = true; if (tvBusinessUnit.CheckedNodes.Count > 1) { lblSelectedBusinessUnit.InnerText += string.Format(" {0}, ", node.Text); } else { lblSelectedBusinessUnit.InnerText = string.Format(" {0}", node.Text); } if (node.Depth == 2) { string nodeVal = node.Text; numselect = numselect + 1; } }

Loop through List Item attachments

Int32 itemID = Convert.ToInt32(item["ID"]); SPListItem theItem = site.RootWeb.Lists[ListName].GetItemById(itemID); if (null != theItem.Attachments) { if (theItem.Attachments.Count > 0) { foreach (string fileName in theItem.Attachments) { SPFile file = SPContext.Current.Site.RootWeb.GetFile(theItem.Attachments.UrlPrefix + fileName); if (theItem.Attachments.Count > 1) { sb.AppendFormat(" {1} , ", string.Format("{0}", SPUtility.ConcatUrls(SPContext.Current.Site.RootWeb.Url, file.Url)), file.Name); } else { sb.AppendFormat(" {1} ", string.Format("{0}", SPUtility.ConcatUrls(SPContext.Current.Site.RootWeb.Url, file.Url)), file.Name); lblAttachments.Text = string.Format("Attachment: {0}", sb.ToString().Trim()); } } if (theItem.Attachments.Count > 1) { lblAttachments.Text = string.Format("Attachments: {0}", sb.ToString() .TrimEnd( ' ' ).TrimEnd( ',' )); } } }