I am newbie to SharePoint and I am uploading a file to the server using javascript. Now the task is to get the GUID of that file and display it ({alert(guid); is fine).

I don't even know where to start. Any help would be really appreciated.

Thanks a lot

I can get the url of the file but I need to display uniqueID/GUID of that file(Item) into RTE.

link|improve this question

40% accept rate
feedback

2 Answers

I'm not so familiar with java client object model for SharePoint, but I have worked with this ajax java script library (SPServices), this is quite useful, works with SharePoint web services and based on jQuery. It allows to query items and so on by calling functions like this:

    $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "Announcements",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
    completefunc: function (xData, Status) {
      $(xData.responseXML).find("[nodeName='z:row']").each(function() {
        var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>";
        $("#tasksUL").append(liHtml);
      });
    }
  });
link|improve this answer
I cannot write "<" or ">" anywhere in the file and hence my caml query does not work... – Thisisme.. Dec 4 '11 at 17:15
escape the characters... < = &lt; > = &gt; – Josey Dec 6 '11 at 20:52
Hi There. Even though your solution might work, MS recommends using the Sharepoint Client Object Model. Have a look at this sample which should work just fine for what you're trying to do. blogs.msdn.com/b/sridhara/archive/2010/03/12/… – Fox Dec 7 '11 at 15:00
This link points to the post about using client object model in C#. I agree client object model is good, but we talk about JavaScript, this is not correct link. Also I dont see any problem in using SharePoint services, it is also provided by Microsoft, this is just wrapper around it. What to use is your choice. – Anton Khritonenkov Dec 10 '11 at 8:50
Thisisme, do you write multiline CAML query, you need to write it in single line, or check this article electrictoolbox.com/javascript-multi-line-strings. It provides guide, how to write multiline strings in JavaScript – Anton Khritonenkov Dec 10 '11 at 9:04
feedback

Here is an example using CSOM in JavaScript.

    var context = new SP.ClientContext.get_current();
    var list = "Name of List";
    var view = "Name of View"; //You can compose a CAML or use a view.
        list = context.get_web().get_lists().getByTitle(listTitle); 
        view = list.get_views().getByTitle(viewTitle); 
        context.load(view); 

    context.executeQueryAsync( 
        function(sender, args) {getLinkListItem("<View><Query>" + view.get_viewQuery() + "</Query></View>")}, 
        function(sender, args) {alert("error: " + args.get_message());});}
    }, 'sp.js')});

 function getLinkListItem(camlQuery){
      var context = SP.ClientContext.get_current();
      var approvalList = context.get_web().get_lists().getByTitle(listTitle);

      var query = new SP.CamlQuery(); 
      query.set_viewXml(camlQuery); 

      listItems = approvalList.getItems(query);
      context.load(listItems);

      context.executeQueryAsync(ReadListItemSucceeded, ReadListItemFailed);
}
//Execute this when you receive the data back from SharePoint.
function ReadListItemSucceeded(sender, args) {
  var enumerator = listItems.getEnumerator();
  while (enumerator.moveNext()) {
    var listItem = enumerator.get_current();
    alert('The ID for ' +listItem.Title + ' is ' + listItem.id);
  }
}
//Execute this function if things go wrong.
function ReadListItemFailed(sender, args) {
  alert('Request failed.');
}

You should also take a look at the MSDN library entry for the JavaScript/ECMA CSOM.

Here is an example using a CAML query rather than a SharePoint view.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.