title: How do you load a file from an absolute NSURL in xamarin
body: <p>I'm developing an App using Xamarin for IOS, used the opengl game template as a start.</p>
  
  <p>I have set up my app to be able to open a certain file format, and have overriden the OpenURL delegate in the AppDelegate.cs</p>
  
  <p>the problem is if I do this:</p>
  
  <pre><code> public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
          {
  
              Stream bob = new FileStream(url.AbsoluteString, FileMode.Open,  FileAccess.Read);
              return true;
          }
  </code></pre>
  
  <p>I get an exception something along the lines of </p>
  
  <pre><code>"Unable to open file : /private/var/mobile/Applications/A7B5E435-F7D1-4985-BA97-C243E63EFC39/MyApp.app/file:///private/var/mobile/Applications/A7B5E435-F7D1-4985-BA97-C243E63EFC39/Documents/Inbox/A%20File%20To%20Open.ext"
  </code></pre>
  
  <p>This seems to be because url.AbsoluteString returns the file:///... part but FileStream always wants a more sanitized path (with the %20s replaced with spaces for example) relative to what must be the app's bundle dir</p>
  
  <pre><code>/private/var/mobile/Applications/A7B5E435-F7D1-4985-BA97-C243E63EFC39/MyApp.app/
  </code></pre>
  
  <p>In the end I got it to work in the very hack way of taking the url.AbsoluteString, removing the "file:///" part, adding a bunch of ../../../ etc to the begining, and replacing "%20" with " ".  </p>
  
  <pre><code> public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
          {
              string fname = "../../../../../../../../../" + (url.AbsoluteString).Replace("%20", " ").Replace("file:///","");
              Stream bob = new FileStream(fname, FileMode.Open,  FileAccess.Read);
              return true;
          }
  </code></pre>
  
  <p>And this worked... but it seems horribly hack.  So what is the correct way to get a readable file stream from an NSURL that points to a file, using Xamarin?</p>
  
  <p>(note this was on IOS 7, in IOS 9, the path passed in is different to FileStream's default dir in many ways and at a high level in the dir tree too)</p>