Stream without C#content

Asked

Viewed 71 times

0

Good afternoon guys I have the following code:

 Stream retorno = new MemoryStream();

        using (var stream = new System.IO.StreamWriter(System.IO.File.Open("c:\\Temp\\file2.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite)))
        {
            infoSerializer.Serialize(stream, Functions.ConvertLayoutConsultarSituacaoLoteRpsEnvio(objeto, Functions.PadraoNFSe(codigoMunicipio)));

            StreamReader reader = new StreamReader(retorno);

            Repositorio.XmlConsultarLote = reader.ReadToEnd();

        }

        using (var stream = new System.IO.StreamWriter(retorno))
        {
            infoSerializer.Serialize(stream, Functions.ConvertLayoutConsultarSituacaoLoteRpsEnvio(objeto, Functions.PadraoNFSe(codigoMunicipio)));

            StreamReader reader = new StreamReader(retorno);

            Repositorio.XmlConsultarLote = reader.ReadToEnd();

        }

The first using is how the function was originally, and the second using is what I’m trying to change, well... the goal and not need to create a physical file on the machine, for this I’m trying instead to create the physical file I’m trying to pass the content to a stream, but on arriving at the Repositorio.XmlConsultarLote = reader.ReadToEnd(); Xmlconsultarlote does not receive anything, guess where the error is?

  • I can’t see now, see: https://answall.com/q/101535/101 and https://answall.com/q/48747/101.

  • The first code already works right??

  • Yes works perfectly

  • 1

    By the question code I cannot understand where you are setting the variable return and that’s probably the problem. Are you sure your code is complete there? I think information is missing, example: where is declared the variable infoSerializer, etc. The more information put the better.

  • The first block also does not assign to Repositorio.XmlConsultarLote nothing but an empty string, since in both Reder is reading Stream retorno = new MemoryStream();. If the first one is working for you, the code that was posted is different from the one running in your application.

  • @Brayan managed to solve?

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.