Can't use NSTexView.FromRtfdFile

Denys de Marcoussis 1 Reputation point
2020-12-11T15:40:36.787+00:00

I begin developing on VisualStudio for MacOs and try to store and reload the rich text content of a NSTextView.
Writing to a file is ok.
Reading with FromRtfdFile don't work.
If I try with ReadDataToEndOfFile it's Ok.
FromRtfdFile is more conveniant for me.
Any idea? Thank you in advance
Don't work :

partial void action_chargeData(NSObject sender)
    {
        NSTextView textView = outlet_data;
        NSUrl url = path("toto.txt"); //path returns the url (controled)
        Console.WriteLine("Read: " + url.ToString());

        if (textView.FromRtfdFile(url.ToString())) //???
            Console.WriteLine("Ok");
        else
            Console.WriteLine("Read error...");
    }

Works fine:

        private void lisFichier()
    {
        NSUrl url = path("toto.txt");
        NSError erreur;
        NSFileHandle fileH = NSFileHandle.OpenReadUrl(url, out erreur);
        if (erreur!=null)
            Console.WriteLine("erreur " + erreur.ToString());
        else
        {
            NSData datas = fileH.ReadDataToEndOfFile();
            NSTextView textView = outlet_data;
            NSRange rang = new NSRange(0, 0);
            textView.ReplaceWithRtfd(rang, datas); //for test
            Console.WriteLine("lu: " + datas.ToString());
        }
    }
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,290 questions
0 comments No comments
{count} votes