Header

Thursday, 20 September 2012

Find the list item attachment url using SPAPI

Webmasters Earn Money Here!
Find the url of the attachments
-------------------------------------------------
function getattachment(id)
{
 var lists = new SPAPI_Lists('http://yoursite/Announcements');
 var items = lists.getAttachmentCollection("Announcements",id);
 if (items.status == 200){

  var rows = items.responseXML.getElementsByTagName('Attachment');
  if (rows.length>0){
   var str="";
   for (var i=0; i<rows.length; i++){
    alert($(rows[i]).text());
    }
   }
  else
  {
   return  "/Announcements/Lists/Announcements/DispForm.aspx?ID="+id;
  }
 }

}
//Here my site is 'http://yoursite/Announcements' and my list name is "Announcements" and id=ID of the item

know wheather the item has any attachment or not
-------------------------------------------------------------------------
function list_itms(itemid)
{
 var lists = new SPAPI_Lists('http://yoursite/Announcements');
 var items = lists.getListItems('Announcements');
 if (items.status == 200)
  {
  var rows = items.responseXML.getElementsByTagName('z:row'); // Get only list rows
      for (var i=0; i<rows.length; i++)
    {
   if (itemid == ows_ID){
    var newid =rows[i].getAttribute('ows_Attachments');
    alert(newid);
   }
    
  }
 }
}
//The above code is to know wheather the item has any attachment or not
//Here my site is 'http://yoursite/Announcements' and my list name is "Announcements" and id=ID of the item

No comments:

Post a Comment