SharePoint

Download attachment from Sharepoint List

Found this useful code snippet to download an attachment from sharepoint list.

SPWeb site = SPContext.Current.Web;

SPFolder folder = site.Folders[“Lists”].SubFolders[“Your List”].SubFolders[“Attachments”].SubFolders[item.ID.ToString()];

foreach (SPFile file in folder.Files)
                            {
                                byte[] imageFile = file.OpenBinary();
                                FileStream fstream = System.IO.File.Create(@”c:\test\image1.png”);
                                fstream.Write(imageFile, 0, imageFile.Length);
                                fstream.Flush();
                                fstream.Close();
                            }

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s