The below method is used to get the files which is attached in the listitem in the custom list
public static FileCollection GetListItemAttachments( string sitePath, string listName, string itemID)
{
try
{
FileCollection oFileCollection=null;
Folder attachmentsFolder = null;
ClientContext clientContext = new ClientContext(sitePath);
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
attachmentsFolder = web.GetFolderByServerRelativeUrl(sitePath + "/Lists/" + listName + "/attachments/" + itemID);
clientContext.Load(attachmentsFolder);
oFileCollection = attachmentsFolder.Files;
clientContext.Load(oFileCollection);
clientContext.ExecuteQuery();
return oFileCollection;
}
catch (Exception ex)
{
throw ex;
}
}
public static FileCollection GetListItemAttachments( string sitePath, string listName, string itemID)
{
try
{
FileCollection oFileCollection=null;
Folder attachmentsFolder = null;
ClientContext clientContext = new ClientContext(sitePath);
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
attachmentsFolder = web.GetFolderByServerRelativeUrl(sitePath + "/Lists/" + listName + "/attachments/" + itemID);
clientContext.Load(attachmentsFolder);
oFileCollection = attachmentsFolder.Files;
clientContext.Load(oFileCollection);
clientContext.ExecuteQuery();
return oFileCollection;
}
catch (Exception ex)
{
throw ex;
}
}
No comments:
Post a Comment