system.UnauthorizedAcceccException in xamarin forms ios

I am trying to open and edit document in xamarin forms ios. This is my code

             public void Save(string filePath, Stream stream)
                {
                    filePath = filePath.RemoveFilePrefix();

                    var fileDir = Path.GetDirectoryName(filePath);
                    if (!string.IsNullOrEmpty(fileDir))
                        CreateDirectory(fileDir);

                    using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
                    {
                        stream.CopyTo(fileStream);
                    }

I am getting this error when execute this code.

Tagged:

Answers

  • ObrockiObrocki Member ✭✭

    What about something like this?

  • ObrockiObrocki Member ✭✭
               var folder = await GetFilesFolder();
                var file = await folder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
    
                using(var writer = await file.OpenAsync(FileAccess.ReadAndWrite))
                {
                    await reader.CopyToAsync(writer);
                }
    
Sign In or Register to comment.