How to programmatically download attachments from list items in Windows SharePoint Services

Article translations Article translations
Article ID: 929259 - View products that this article applies to.
Expand all | Collapse all


This article describes how to programmatically download attachments from list items in Microsoft Windows SharePoint Services.


The attachments of a list item are stored in the Web folder in the following structure:
The following code is an example of code that you can use to programmatically download attachments from list items.
	SPWeb web = new SPSite("<Site URL>").OpenWeb();
		//Open List
		SPList list = web.Lists["<ListName>"];
		//Get the item
		SPListItem item = list.Items[1];
		//Get the folder
		SPFolder folder = web.Folders["Lists"].SubFolders[strListName].SubFolders["Attachments"].SubFolders[item.ID.ToString()]; 
		foreach(SPFile file in folder.Files)
			byte[] binFile = file.OpenBinary();
			System.IO.FileStream fstream = System.IO.File.Create("c:\\MyDownloadFolder\\" + file.Name);	
			fstream.Write(binFile, 0, binFile.Length);


Article ID: 929259 - Last Review: December 20, 2006 - Revision: 1.1
  • Microsoft Windows SharePoint Services 2.0
kbexpertiseinter kbexpertisebeginner kbhowto KB929259

Give Feedback


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from