I have filled up a List with many elements of "Hello".
Now I wonder how it is possible to use MemoryStream to "chunk" this and append it to an existing file.("C:\\OutFile.txt")
I have googled around on examples for 2 days without really understand how to do this.

I have understand that I need to write to memorystream and from here in somehow write from memorystream but it just leaves me with these words.

My beginning code is like follows. How can I do this ? Thank you.

List<String^>^ FillUp = gcnew List<String^>();
for (int i = 0; i < 1000000; i++) 
{ 
     FillUp->Add("Hello"); 
}

String^ OutPath = "C:\\OutFile.txt";

FileStream^ fs = gcnew FileStream(OutPath, FileMode::Append, FileAccess::ReadWrite); 
StreamWriter^ WriteToFile = gcnew StreamWriter(fs);

FileAccess must be FileAccess:Write when FileMode::Append is used.

List<String^>^ FillUp = gcnew List<String^>();
	for (int i = 0; i < 10; i++){  
        FillUp->Add("Hello"); 
    }
    
 MemoryStream^ ms=gcnew MemoryStream();	
 for each(String^ s in FillUp){
    array<Byte>^ b=System::Text::Encoding::UTF8->GetBytes(s);
    ms->Write(b,0,b->Length);
 }

 String^ OutPath = "C:\\csnet\\OutFile.txt";
 FileStream^ fs = gcnew FileStream(OutPath, FileMode::Append,  
                                             FileAccess::Write); 
 ms->WriteTo(fs);
 fs->Flush();
 fs->Close();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.