I figured out! It is apparently because I did not include a fileexist check before trying to open it.
I have re written the code like this
IStorageFolder dataFolder = await local.CreateFolderAsync("Page", CreationCollisionOption.OpenIfExists);
StorageFile Ink_File = null;
//Using try catch to check if a file exists or not as there is no inbuilt function yet
try
{
Ink_File = await dataFolder.GetFileAsync("testpng.png");
}
catch (FileNotFoundException)
{
return false;
}
try
{
if (Ink_File != null)
{
using (var testpng = await Ink_File.OpenStreamForWriteAsync())
{
i.WritePNG(testpng);
testpng.Flush();
testpng.Close();
return true;
}
}
}
catch(Exception e)
{
string txt = e.Message;
return false;
}
return false;