0

I'm implementing a RER (remote event receiver) in a provider-hosted app with CSOM, I need the FileRef property of the file which was just uploaded, so how can I get it?

any help would be appreciated.

thanks

2
var fileName = "Document.docx";

ClientContext clientContext = new ClientContext("http://sitecollectionurl"); 
Microsoft.SharePoint.Client.List spList = clientContext.Web.Lists.GetByTitle("Test"); 
clientContext.Load(spList); 
clientContext.ExecuteQuery(); 

if (spList != null && spList.ItemCount > 0) 
{
    Microsoft.SharePoint.Client.CamlQuery camlQuery = new CamlQuery(); 
    camlQuery.ViewXml = 
     @"<View>  
           <Query> 
              <Where><Eq><FieldRef Name='FileLeafRef' /><Value Type='File'>"+fileName+@"</Value></Eq></Where> 
           </Query> 
            <ViewFields><FieldRef Name='FileRef' /><FieldRef Name='FileLeafRef' /></ViewFields> 
     </View>";  

    ListItemCollection listItems = spList.GetItems(camlQuery); 
    clientContext.Load(listItems); 
    clientContext.ExecuteQuery();

    var listItem = listItems.FirstOrDefault();
    var value = Convert.ToString(listItem["FileRef"]);
}
  • it works just great! thanks, one more question, in case that I need antoher field like for example ContentType where can i see the references of the fields for put them in the caml query. – Emmanuel Villegas Nov 30 '16 at 16:13
  • add it inside ViewFields tag. example <ViewFields><FieldRef Name='FileRef' /><FieldRef Name='FileLeafRef' /><FieldRef Name='ContentType' /></ViewFields> – Gautam Sheth Nov 30 '16 at 16:16
0

It worked for me when i replaced Eq with Contains operator and type as Text

 @"<View>  
       <Query> 
          <Where><Contains><FieldRef Name='FileLeafRef' /><Value Type='Text'>"+fileName+@"</Value></Contains></Where> 
       </Query> 
        <ViewFields><FieldRef Name='FileRef' /><FieldRef Name='FileLeafRef' /></ViewFields> 
 </View>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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