Special Characters(#, %) File Not Found when loading ListItem -> File -> Properties

Copper Contributor

With the addition of the new special characters we have come into a hiccup trying to support them in our 365 solution. The problem seems to occur when we attempt to load anything to do with a ListItem.File if we already have the ServerRelativeUrl for the file. 

 

For example the code path below(where cxt is a ClientContext):

cxt.Load(listItem.File)

cxt.ExecuteQuery()

cxt.Load(listItem.File.Properties)

cxt.ExecuteQuery() 

 

The last line will always throw a "File Not Found" exception in this scenario.

 

However if executed the other way around no exception is thrown. This only occurs on files with special characters in the filename and due to the many code paths we have we would need a major refactor to make sure we never have the ServerRelativeUrl before loading a File.

Not sure if this is the right forum, but does anyone know of easier workarounds for this or how to raise it with the 365 devs

4 Replies

Detailed Repro steps :

1. Create 2 documents. One with a # or % in the file name, and one with neither of these characters

2. Create a ClientContext.

3. Get the existing ListItem objects through the context. (you should get a reference for both of the previously created files)
4. Execute the following code, where listItem is the ListItem with no special characters, and listItemSpecial is the Listitem with a # or %:
 
cxt.Load(listItem.File);
cxt.ExecuteQuery();
cxt.Load(listItem.File);
cxt.ExecuteQuery();
 
cxt.Load(listItemSpecial.File);
cxt.ExecuteQuery();
cxt.Load(listItemSpecial.File);
cxt.ExecuteQuery();
 
 
NOTE: The above code is not meant to be a realistic snapshot of how this bug occurrs in our code. It is simply the fastest way to reproduce the behaviour.
In reality, the above bug occurs when we load a file, and then try to access one of its properties a lot later in the code using the same context.
for example: 
 
File file = listItem.File;
cxt.Load(file);
cxt.ExecuteQuery();
 
**we pass the file to a few different methods here**
 
if (file.Properties == null || file.Properties.FieldValues.Count == 0)
{
     cxt.Load(file.Properties);
     cxt.ExecuteQuery();
}




One question here: did you enable # and % support in your tenant? It might happen the source of the problem is just this...
Yes, # and % support was enabled for the tenant