Freigeben über


SharePoint : How to programmatically download attachments from the List Items

Note: The following is example code. It is not available in SharePoint SDK

SPWeb web = new SPSite(" https://karthickmain:8080/sites/test").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);
}

Comments