1

I am new to Blazor but not mpxj. I have managed to create Blazor code to open a local file into a stream. Then attempting to convert to Java stream using ikvm.io.InputStreamWrapper(stream);. When I debug stream contains data but after conversion javastream is empty. Any help appreciated.

@using net.sf.mpxj;
@using Microsoft.AspNetCore.Components.Forms;

@page "/"

<PageTitle>Index</PageTitle>

<InputFile OnChange="@SelectFile" accept=".xer"/>

 
<button type="button" @onclick="ReadFile">Read file</button>

@code
{
    IBrowserFile? file;
    int MAXSIZE = 500000;


    private void SelectFile(InputFileChangeEventArgs e)
    {
        file = e.File;
    }

    private async System.Threading.Tasks.Task ReadFile()
    {
        var stream = new MemoryStream();
        await file.OpenReadStream(MAXSIZE).CopyToAsync(stream);

        java.io.InputStream javaStream = new ikvm.io.InputStreamWrapper(stream);

        net.sf.mpxj.reader.UniversalProjectReader reader = new net.sf.mpxj.reader.UniversalProjectReader();
        ProjectFile projectFile = reader.read(javaStream);
    }

}

  • There is a [separate wrapper class shipped with MPXJ](https://github.com/joniles/mpxj/blob/master/src.net/utilities/DotNetInputStream.cs) which is intended to do the same as the `InputStreamWrapper`. Might be worth giving that a try? Alternatively you could either pass the file name to the reader class, rather than a stream? – Jon Iles Aug 21 '23 at 13:41

0 Answers0