Click here to Skip to main content
15,116,354 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to all,
byte[] storage = new byte[3000000];
Stream fileStream = Stream.Null;
MemoryStream memoryStream = new MemoryStream(storage);
TextWriter streamWriter = new StreamWriter(memoryStream);
streamWriter.WriteLine("Companies Information");

// Writing Data into the File...
List<CompanySearchResultItem> list = SearchCompany(businessEntitySearchArgs);
// iterate to the list and print the remaining rows.
foreach (CompanySearchResultItem item in list)


byte[] CompanyData = new byte[memoryStream.Length];
fileStream.Write(CompanyData, 0, (int)memoryStream.Length);

This is my code. I need data in CompanyData but I was not able to get it. Please help me.
Updated 6-Oct-10 10:07am
HimanshuJoshi 6-Oct-10 9:24am
Edited for code-block
Toli Cuturicu 6-Oct-10 15:06pm
Poor edit, HimanshuJoshi. Don't forget to add lang="cs" or esle keywords won't get highlighted properly.

Use this that may solve your problem,

byte[] CompanyData = new byte[uniEncoding.GetByteCount(memoryStream)];
        0, uniEncoding.GetByteCount(memoryStream));

Hope it helps.

Please vote and Accept Answer if it Helped.
Why are you doing it that way? Why don't you just create/open a text file, and write the names? That would be no more than five or six lines of code, and easiser to maintain as well.
If you want the data in the array CompanyData, why don't you just use memoryStream.ToArray()?
Or at least use Read instead of Write..
BlackCat_RU 7-Oct-10 2:40am
I agree. memoryStream.ToArray() will create a copy of its actually filled buffer and return byte[] array.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900