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( ',' )); } } }
Cloud development @ its best. Snippets, ideas, latest, best practices etc.