Search code examples
c#xamarinportable-class-libraryxamarin.mac

Xamarin - Shared Class Library Accessing System.IO.File


I try to create a really simple app containing

  • Windows Version
  • Mac Version
  • Portable Class Library

I would like to put the code (as much as possible) into the Portable Class Library. Now i simply want to check if a file exists using System.IO.File.Exists() but the File object is not available. I tryed to target different plattforms but i cant get it to work.


Solution

  • System.IO.File is not available in the PCL code. You will need to implement in platform specific code. You will also need to verify that it exists for each platform. I know it does for Android and iOS, have never tried using it on Mac and Windows. Although from Xamarin's docs it looks like at least Mac does have System.IO.File.

    Once you have methods in each platform project, you can reference the platform specific method from your PCL code using Xamarin's Dependency Service.