Skip to content
Skip to content
CTASoftware Blog

Para Desenvolvedores De Software

  • Sobre Mim
← Obter Usuário Por Id SharePoint
Atualizar List Item SharePoint →
-->

Obtém anexos de Lista SharePoint

Posted on 12 de setembro de 2017 by Everton Gonçalves

Function para obter a lista de anexos de uma lista no SharePoint.

[js]
function ObtemAnexos(listItem) {
var ctx = listItem.get_context();
var attachmentFolderUrl = String.format(‘{0}/Attachments/{1}’,listItem.get_fieldValues()[‘FileDirRef’],listItem.get_fieldValues()[‘ID’]);
var folder = ctx.get_web().getFolderByServerRelativeUrl(attachmentFolderUrl);
var files = folder.get_files();
ctx.load(files);

ctx.executeQueryAsync(
function () {
var attachments = [];
for (var i = 0; file = files.get_item(i) ; i++)
{
attachments.push({url: file.get_serverRelativeUrl(), name: file.get_name()});
}
return attachments;
});
}
[/js]

Caso queira montar uma div com os anexos

[js]
function ObtemAnexos(listItem) {
var ctx = listItem.get_context();
var attachmentFolderUrl = String.format(‘{0}/Attachments/{1}’,listItem.get_fieldValues()[‘FileDirRef’],listItem.get_fieldValues()[‘ID’]);
var folder = ctx.get_web().getFolderByServerRelativeUrl(attachmentFolderUrl);
var files = folder.get_files();
ctx.load(files);

ctx.executeQueryAsync(
function () {
var attachments = [];
htmlAnexo = ‘

‘;
for (var i = 0; file = files.get_item(i) ; i++)
{
attachments.push({url: file.get_serverRelativeUrl(), name: file.get_name()});
htmlAnexo += ‘‘ + file.get_name() + ‘
‘;
}
htmlAnexo += “

“;
var xxx = listItem.get_fieldValues()[‘ID’];
if(htmlAnexo != undefined){
$(‘[id^=”idAnexoCampanha”]’).html(htmlAnexo);
}
$(‘body’).append(htmlAnexo);

return attachments;
});
}
[/js]

Até a próxima

Compartilhe isso:

  • Clique para compartilhar no Twitter(abre em nova janela)
  • Clique para compartilhar no Facebook(abre em nova janela)
  • Clique para compartilhar no WhatsApp(abre em nova janela)
  • Clique para compartilhar no Telegram(abre em nova janela)
  • Clique para compartilhar no LinkedIn(abre em nova janela)
  • Clique para enviar um link por e-mail para um amigo(abre em nova janela)

Relacionado

About Everton Gonçalves

http://www.ctasoftware.com.br
View all posts by Everton Gonçalves
This entry was posted in JavaScript, JQuery, SharePoint and tagged Anexos SharePoint, SharePoint, SharePoint JavaScript, SharePoint Jquery, SharePoint Obter Anexos. Bookmark the <a href="https://www.ctasoftware.com.br/blog/obtem-anexos-de-lista-sharepoint/" title="Permalink to Obtém anexos de Lista SharePoint" rel="bookmark">permalink</a>.
← Obter Usuário Por Id SharePoint
Atualizar List Item SharePoint →

Deixe um comentário Cancelar resposta

Você precisa fazer o login para publicar um comentário.

© 2026 | Blog info WordPress Theme | By Bharat Kambariya