MemoryStream to File

Lec11Lec11 Member Posts: 91
edited 2015-06-26 in NAV Three Tier
Hello,

I am trying to read some data from a memory stream and write it to a file using DotNet variables in Nav 2013. I am not a DotNet specialist but I found some code on the web and tried to adapt it:
Filepath := FileMgmt.ClientTempFileName('txt');
FileMode := FileMode.Create();
FileAccess := FileAccess.Write();
FileStr := FileStr.FileStream(FilePath,FileMode,FileAccess);
MemoryStream.WriteTo(FileStr);
FileStr.Close();
MemoryStream.Flush();
MemoryStream.Close();

But I am getting the following error:
Microsoft Dynamics NAV

A call to System.Net.ConnectStream.WriteTo failed with this message: The type of one or more arguments does not match the method's parameter type.
OK

From what I see, the WriteTo method support a stream parameter. Isn't it the same with FileStream?
Can anybody throw an advice on this? Or maybe guide me to the proper way of doing it?

Regards!

Comments

  • vremeni4vremeni4 Member Posts: 323
    Hi,

    Take a look at this link
    http://www.mibuso.com/forum/viewtopic.php?f=7&t=58425&hilit=ftp
    The code uses extensively streams, so you will definitely find differtn example for what you need.

    I hope this helps.
    Thanks.
  • ephraimdovephraimdov Member Posts: 1
    try this

    string memString = "Memory test string !!";
    // convert string to stream
    byte[] buffer = Encoding.ASCII.GetBytes(memString);
    MemoryStream ms = new MemoryStream(buffer);
    //write to file
    FileStream file = new FileStream("d:\\file.txt", FileMode.Create, FileAccess.Write);
    ms.WriteTo(file);

    Source....MemoryStream to File

    Dov
Sign In or Register to comment.