Get ID from file name

Apr 17, 2012 at 1:37 PM

Can I get a file ID from a file name with a web service? I've been trying to use the GetListItems filtering on the ServerUrl field like below, but it does not work. Any suggestions?

<Eq><FieldRef Name="ServerUrl"/><Value Type="Text">'+serverUrl+'</Value></Eq>

<Eq><FieldRef Name="ServerUrl"/><Value Type="Computed">'+serverUrl+'</Value></Eq>
/Fredrik

Apr 17, 2012 at 1:53 PM

By file ID you mean the item's ID in the SharePoint library correct? In that case under CAMLViewFields: "<ViewFields>" you'll want to add + "<FieldRef Name='ID' />"

Under completefunc: function (xData, Status) {

you'll add something like var ID = $(this).attr("ows_ID");

Then you can do whatever you want with that ID variable i.e. alert(ID);

Let us know if this isn't what you're looking for.

Apr 17, 2012 at 2:19 PM

The problem is that I have a file url (returned from the field _CopySource in another list). From this URL I need to get the ID field as you mention, but using possible fields like ServerUrl or EncodedAbsUrl in the CAML query like above results in the error message below

 

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.</faultstring>
<detail>
<errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/">Invalid column name 'c11'.</errorstring>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>

I don't think there is another error in the query since it works perfectly fine if i filter on title instead of ServerUrl.
$().SPServices({
	webURL: webDomain+'/pro/ul/se',
	operation: "GetListItems",
	listName: 'Pages',
	CAMLViewFields: '<ViewFields><FieldRef Name="ID"/></ViewFields>',
	CAMLQuery: '<Query><Where><Eq><FieldRef Name="ServerUrl"/><Value Type="Computed">'+serverUrl+'</Value></Eq></Where></Query>',  // query 
	CAMLRowLimit: 1,
	CAMLQueryOptions: '<QueryOptions><IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns><ViewAttributes Scope="RecursiveAll" IncludeRootFolder="True" /></QueryOptions>',  // queryOptions
	completefunc: function (xData, Status) {
		alert(Status+': '+xData.responseText);	
	}

});

Apr 17, 2012 at 3:04 PM

Using 

<FieldRef Name="FileRef"/><Value Type="Lookup">

works better, can't make the field ServerUrl work

 

/F