Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
C#
public static byte[] ReadFile(string filePath)
{
    byte[] buffer;
    FileStream fileStream = new FileStream(@"c:\as.txt", FileMode.Open, FileAccess.Read);
    try
    {
        int length = (int)fileStream.Length;  // get file length
        buffer = new byte[length];            // create buffer
        int count;                            // actual number of bytes read
        int sum = 0;                          // total number of bytes read

        // read until Read method returns 0 (end of the stream has been reached)
        while ((count = fileStream.Read(buffer, sum, length - sum)) > 0)
            sum += count;  // sum is a buffer offset for next reading
    }
    finally
    {
        fileStream.Close();
    }
    return buffer;
}
Posted
Updated 22-Nov-11 2:16am
v2
Comments
Zubair Alie 22-Nov-11 8:20am    
it looks like you are programming in c#. see inside your program.cs file inside your project.
go inside Main method to see that on Run, which form you are pointing.
Sergey Alexandrovich Kryukov 22-Nov-11 23:05pm    
And what's the problem? Error message tells you what to do, why would not you just follow it?
--SA

Main is the entry-point for a C# application, see, for instance, here
"Program Entry point in C#"[^].
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 22-Nov-11 23:06pm    
Sure, a 5.
--SA
CPallini 23-Nov-11 3:47am    
Thank you.
Write a main method and call you function from it. I think you have deleted it
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 22-Nov-11 23:06pm    
Yes it happens, but the OP's problem is inability to understand this very clear error message. My 5.
--SA

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