We take pride in your success. We let our positivity drive us, day in and out. Talk to us at Mindfire to know us more.

Software Technology Tips

As we can have multiple attachments against a list item, it has always been a requirement to fetch these attachments and get it displayed within a custom webpage.
 
Below is code snippet in c#.net for fetching all the attachements for a specific list item.
try
            {
                // Set the Site Url
                SPSite objSite = new SPSite("http://Testsite/");
 
                using (SPWeb objWeb = objSite.OpenWeb())
                {
                    objWeb.AllowUnsafeUpdates = true;
 
                    // Get the List
                    SPList objList = objWeb.Lists["MyList"];
 
                    // Get the item by ID
                    SPListItem objItem = objList.GetItemById(1);
 
                    // Get the attachments of the item
                    SPAttachmentCollection objAttchments = objItem.Attachments;
 
                    // Iterate the attachments
                    foreach (string fileName in objItem.Attachments)
                    {
                        // Perform action on the extracted attachment
                    }
 
                   objWeb.AllowUnsafeUpdates = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


Related Tags:

SharePoint

Author: Samarendra Swain

top

SharePoint

Let us Connect!

privacy

copyright (c) Mindfire Solutions 2007-2012. Login