I don't think you can get the unique id for the list attachments but you can get item id for the attachments. try with the below code.
using Microsoft.SharePoint.Client;
using NLog;
using System;
using System.IO;
using System.Net;
namespace SiteActions.Task
{
class Program
{
//You can get NLog from NuGet
//http://www.nuget.org/packages/nlog
private static Logger logger = LogManager.GetCurrentClassLogger();
static void Main(string[] args)
{
try
{
int startListID;
Console.WriteLine("Enter Starting List ID");
if (!Int32.TryParse(Console.ReadLine(), out startListID))
{
Console.WriteLine("Invalid ID");
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
return;
}
String siteUrl = "http://siteaction.net/sites/teamsite";
String listName = "SharePoint List Name";
NetworkCredential credentials =
new NetworkCredential("username", "password", "domain");
using (ClientContext clientContext = new ClientContext(siteUrl))
{
Console.WriteLine("Started Attachment Download " + siteUrl);
logger.Info("Started Attachment Download" + siteUrl);
clientContext.Credentials = credentials;
//Get the Site Collection
Site oSite = clientContext.Site;
clientContext.Load(oSite);
clientContext.ExecuteQuery();
// Get the Web
Web oWeb = clientContext.Web;
clientContext.Load(oWeb);
clientContext.ExecuteQuery();
CamlQuery query = new CamlQuery();
query.ViewXml = @"";
List oList = clientContext.Web.Lists.GetByTitle(listName);
clientContext.Load(oList);
clientContext.ExecuteQuery();
ListItemCollection items = oList.GetItems(query);
clientContext.Load(items);
clientContext.ExecuteQuery();
foreach (ListItem listItem in items)
{
if (Int32.Parse(listItem["ID"].ToString()) >= startListID ){
Console.WriteLine("Process Attachments for ID " +
listItem["ID"].ToString());
Folder folder =
oWeb.GetFolderByServerRelativeUrl(oSite.Url +
"/Lists/"+listName+/Attachments/" +
listItem["ID"]);
clientContext.Load(folder);
try
{
clientContext.ExecuteQuery();
}
catch (ServerException ex)
{
logger.Info(ex.Message);
Console.WriteLine(ex.Message);
logger.Info("No Attachment for ID " + listItem["ID"].ToString());
Console.WriteLine("No Attachment for ID " + listItem["ID"].ToString());
}
FileCollection attachments = folder.Files;
clientContext.Load(attachments);
clientContext.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.File oFile in folder.Files)
{
logger.Info("Found Attachment for ID " +
listItem["ID"].ToString());
Console.WriteLine("Found Attachment for ID " +
listItem["ID"].ToString());
FileInfo myFileinfo = new FileInfo(oFile.Name);
WebClient client1 = new WebClient();
client1.Credentials = credentials;
logger.Info("Downloading " +
oFile.ServerRelativeUrl);
Console.WriteLine("Downloading " +
oFile.ServerRelativeUrl);
byte[] fileContents =
client1.DownloadData("http://siteaction.net" +
oFile.ServerRelativeUrl);
FileStream fStream = new FileStream(@"C:Temp" +
oFile.Name, FileMode.Create);
fStream.Write(fileContents, 0, fileContents.Length);
fStream.Close();
}
}
}
}
}
catch (Exception e)
{
logger.ErrorException(e.Message, e);
logger.Error(e.StackTrace);
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
}
}
}
Ref: https://social.technet.microsoft.com/Forums/office/en-US/3881057d-6a43-4f07-8387-23d6a6dd9648/sharepoint-list-items-get-attachments-c-console-app?forum=sharepointgeneral
Thanks & Regards,
Sharath Aluri