Check if file exist


I would like to check if a file exist so I don’t get a runtime error but the usual tricks I use in JS does not work in fuse. How would the “fileExist” function look like?


<Image File="{photoFile}" Width="40" Height="40" StretchMode="Uniform" Margin="0,3,0,0"/>


vPhotoFile = "Assets/friends/" + friendName + ".jpg";

if fileExist(vPhotoFile) {
    photoFile.value = vPhotoFile;
} else {
    photoFile.value = "Assets/friends/DEFAULT.jpg";

I decided to create a uno function but I always get a false. How do I get the base directory ?

static object FileExist(Context c, object[] args)

    if (args.Length != 1) throw new Error("FileExist(): takes 1 argument, " + args.Length.ToString() + " provided");

    string filepath = args[0] as string;

    if (filepath == null) {
        return false;
    } else {
        if (Uno.IO.File.Exists(filepath)) {
            return true;
        } else {
            return false;

Where do you get the file from? (This matters on where and how to check for it. )

sorry! i thought it was clear in the example:

the file is in the same directory where the “MainView.ux” is

Perhaps you need to do something like Uno.UI.Bundle.Get().GetFile(filepath).IsFile instead?