Forum Xamarin.Forms

How to save a file in Xamarin Forms, .net standard without PCL ?

SteeveDessSteeveDess Member ✭✭
edited February 2018 in Xamarin.Forms

Hi,

I'm looking for a way to save an xml file, in a solution with Android, Ios and UWP prjetcs.

I'm using c#, Xamarin forms 2.5, vs 2017 15.5.5, and a shared library solution, .Net standard 2.0, without PCL.

How can I do that ?

Regards

Steeve

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    Can't use System.IO?

  • SteeveDessSteeveDess Member ✭✭

    Hi,

    I tried that :

    FileStream fileStream = new FileStream(fileName.Replace(".xml", "out.xml").ToString(), FileMode.CreateNew);
    doc.Save(fileStream);
    fileStream.Close();

    But I've this exception :
    System.UnauthorizedAccessException
    HResult=0x80070005
    Message=Access to the path 'C:\Projets\mobilotis\mobiLotis\mobiLotis.UWP\bin\x86\Debug\AppX\Test Promesse de venteout.xml' is denied.
    Source=System.Private.CoreLib
    Arborescence des appels de procédure :
    à System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
    à System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
    à System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
    à System.IO.FileStream..ctor(String path, FileMode mode)
    à mobiLotis.Services.WordFusionManager.Amalgamate(String fileName, Byte[] data, IList listeObjetsRemplacement) dans C:\Projets\mobilotis\mobiLotis\mobiLotis\Services\WordFusionManager.cs :ligne 49
    à mobiLotis.ViewModels.VM_Reservation.d__132.MoveNext() dans C:\Projets\mobilotis\mobiLotis\mobiLotis\ViewModels\VM_Reservation.cs :ligne 223

    I think I need to know where to save the file, but I don't know how, All I can find is using the PCLStorage nuget extension, But I'n not in a PCL solution.

    How do we do that in the new concept of .Net standard ?

    Steeve

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    It seems an authorization priblem.
    Try to change the directory
Sign In or Register to comment.