0

I am trying to select a file in the Finder, that is not happening the method works well in Obj-C but in Xamarin Finder gets activated but the file is not getting selected.

Whereas if I use Xamarin command to open the file it opens.

Here is the snippet of code that I wrote. Guide me if I am doing something wrong or missing anything?

public override void DidFinishLaunching(NSNotification notification)
{

    string fullPath = "/Users/anoopvaidya/Desktop/A/ClientInfoConfig.cs";

    NSUrl url = NSUrl.FromString(fullPath);

    NSUrl[] urls = { url };


    NSWorkspace.SharedWorkspace.OpenFile(fullPath); 
   //works. But I only want to select in Finder

    NSWorkspace.SharedWorkspace.ActivateFileViewer(urls); 
   //doesn't work

}

Is it related to OS version? I am using 10.13.6.

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • `Whereas if I use Xamarin command to open the file it opens.` What exactly do you mean here? – FreakyAli Dec 21 '18 at 11:20
  • @G.hakim: Open means, if I pass .cs it opens in VS, if I pass .jpg it opens in preview. i.e. the file opens in the default app. – Anoop Vaidya Dec 21 '18 at 11:56

1 Answers1

0

You need to use a file:// based url:

Example:

using (var url = new NSUrl("file", "localhost", "/Users/Sushi/Desktop/StackOverflow.png"))
{
    NSWorkspace.SharedWorkspace.ActivateFileViewer(new NSUrl[] { url });
}
SushiHangover
  • 73,120
  • 10
  • 106
  • 165