Retrieving an attachment from an item using code

foreach (SPListItem attachItem in list.Items){if (Convert.ToString(attachItem["Request Number"]) == Convert.ToString(this.Page.Request.QueryString["reqno"])){foreach (string fileName in attachItem.Attachments){SPFile file = attachItem.ParentList.ParentWeb.GetFile(attachItem.Attachments.UrlPrefix + fileName);writer.RenderBeginTag(HtmlTextWriterTag.Tr);writer.AddAttribute(HtmlTextWriterAttribute.Target, "_blank");writer.AddAttribute(HtmlTextWriterAttribute.Href, file.ServerRelativeUrl);writer.AddStyleAttribute(HtmlTextWriterStyle.FontSize, "12px");writer.RenderBeginTag(HtmlTextWriterTag.A);writer.Write(file.Name);writer.RenderEndTag();flag = true;}break;}}


Attaching a file to an item using code

If you are using a custom newform.aspx then you will face difficulties in adding attachments. There are two scenariosIf you make your own infopath forms/user control then you will not be having the attachments option If you remove any columns(Default for that list) using sharepoint designer , you will have the option for attachments but... Continue Reading →

Create a website or blog at

Up ↑

%d bloggers like this: