3

I'm trying to get the ContentTypeId of an item in sharepoint to get the full url of the item to get the binary of it and after send it to another plateform.

So here i put this code in element.xml to get the list ID and the document ids of the items i'm selecting, after this i send them to an ASPX page in a Sharepoint Dialog to define the destination of the items and after this in the postback, stream the binary and send it to the another platform. The problem is : To get the full url of my items i need ListId, ItemId and ContentTypeId. Because i've found a code to stream the binary here : How to Programatically Download files from sharepoint document library

And i need the full url of my items.

Any idea?

thanks

var iddocs ='';
var listId ='';
function geturl()
{
  var context = SP.ClientContext.get_current();
  this.web = context.get_web();
  listId = SP.ListOperation.Selection.getSelectedList(); 
  var list = this.web.get_lists().getById(listId);
  var ok = false;
  try
  {
    if ( SP.ListOperation.Selection.getSelectedItems(context) !== false)    
    {
      var items = SP.ListOperation.Selection.getSelectedItems(context);
      var url='listId:'+listId+ ' Number of selected items: ' + items.length ;
      var i = 0;
      if(items.length==0)
      {
      }else{
        while( i != items.length )
        {
          url += ' Doc' + i + ': ' + items[i].id;
          if(i>0){iddocs += '-'};
          iddocs += items[i].id;
          i++;
        };
        ok = true;
        alert(url+' Id of clicked item:'+{ItemId});
        };
    };
  }
  catch(err)
  {
  };
return ok;
};        
function OpenDialog(pidliste) {
    var options = SP.UI.$create_DialogOptions();
    options.width = 600;
    options.height = 600;
    options.title = 'Envoyer vers Nuxeo';
    options.url ='/_Layouts/SPTest.CustomMenuItem/index.aspx?click={ItemId}';
    if(pidliste){options.url += '&ids='+pidliste +'-'+ iddocs;};
    options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
    SP.UI.ModalDialog.showModalDialog(options);
}
function CloseCallback(result, target) {
    if (result == SP.UI.DialogResult.OK) {
    }
    if (result == SP.UI.DialogResult.cancel) {
        SP.UI.Notify.addNotification('Opération canceled', false, '', null);
    }
}
if(geturl())
{
    OpenDialog(listId);
}else{
    alert('Please select an item');
};
Community
  • 1
  • 1

1 Answers1

1

I've found the solution. In fact, items can be reached via :

{SiteUrl}+{ItemUrl}

The download function is linked in my first Post. But it doesn't work for multiple items, with this method you can only reach the properties of the item you're selecting.

You have to note that if you want to access to a SP file, you have to set your request.credential via :

request.Credentials = System.Net.CredentialCache.DefaultCredentials;

which will take the current credential you're using.

Hope it helps.