zaulin
April 7, 2016, 2:47pm
1
Hi!
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?
UX:
<Image File="{photoFile}" Width="40" Height="40" StretchMode="Uniform" Margin="0,3,0,0"/>
JS:
vPhotoFile = "Assets/friends/" + friendName + ".jpg";
if fileExist(vPhotoFile) {
photoFile.value = vPhotoFile;
} else {
photoFile.value = "Assets/friends/DEFAULT.jpg";
}
zaulin
April 7, 2016, 5:28pm
2
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. )
zaulin
April 7, 2016, 7:30pm
4
sorry! i thought it was clear in the example:
the file is in the same directory where the “MainView.ux” is
kusma
April 15, 2016, 12:14pm
5
Perhaps you need to do something like Uno.UI.Bundle.Get().GetFile(filepath).IsFile instead?