Click here to Skip to main content
15,897,334 members
Home / Discussions / C#
   

C#

 
GeneralRe: "How Get Type of File ? Pin
Bahadir Cambel3-Jan-05 10:22
Bahadir Cambel3-Jan-05 10:22 
GeneralRe: "How Get Type of File ? Pin
DavidNohejl3-Jan-05 10:51
DavidNohejl3-Jan-05 10:51 
GeneralRe: "How Get Type of File ? Pin
Bahadir Cambel3-Jan-05 11:42
Bahadir Cambel3-Jan-05 11:42 
General.NET Remote - Activator.GetObject Pin
Wender Oliveira3-Jan-05 5:21
Wender Oliveira3-Jan-05 5:21 
GeneralRe: .NET Remote - Activator.GetObject Pin
Adam Goossens9-Jan-05 23:48
Adam Goossens9-Jan-05 23:48 
GeneralFile to byte[ ] Pin
WDI3-Jan-05 4:43
WDI3-Jan-05 4:43 
GeneralRe: File to byte[ ] Pin
Wender Oliveira3-Jan-05 5:15
Wender Oliveira3-Jan-05 5:15 
GeneralRe: File to byte[ ] Pin
Dennis C. Dietrich3-Jan-05 7:40
Dennis C. Dietrich3-Jan-05 7:40 
Wender Oliveira wrote:
just change your max file size and filepath...

const int MaxSize = 1000;
string FilePath = @"C:\test.txt";

byte[] b = new byte[MaxSize];
FileStream f = new FileStream(FilePath,FileMode.Open);
f.Read(b,0,(int)f.Length);


No. I've seen it many times and it is just wrong. You end up with an array with then length 1000. How does that reflect the content of the array? It doesn't. The object processing the array has to analyze the data in order to find out the length of the actual user data (sometimes that might even be impossible). And what if MaxSize is much larger? Just read the entire file as originally asked for and if you want to introduce a limit then use something like this (and make sure the receiving object is aware of the fact that the data might be truncated):
byte[] MyArray = null;
const int MaxSize = 1000;
string FilePath = @"C:\test.txt";
FileInfo MyFile = new FileInfo(FilePath);

if (MyFile.Length > MaxSize)
  MyArray = new byte[MaxSize];
else
  MyArray = new byte[MyFile.Length];

Best regards
Dennis
QuestionHow to build patch Pin
Newbie_Toy3-Jan-05 3:34
Newbie_Toy3-Jan-05 3:34 
GeneralSaving Text Versions Pin
Darren Pruitt3-Jan-05 3:19
Darren Pruitt3-Jan-05 3:19 
GeneralRe: Saving Text Versions Pin
leppie3-Jan-05 5:55
leppie3-Jan-05 5:55 
GeneralInterfaces Pin
Bahadir Cambel3-Jan-05 0:05
Bahadir Cambel3-Jan-05 0:05 
GeneralRe: Interfaces Pin
jan larsen3-Jan-05 1:32
jan larsen3-Jan-05 1:32 
GeneralRe: Interfaces Pin
Bahadir Cambel3-Jan-05 8:59
Bahadir Cambel3-Jan-05 8:59 
GeneralRe: Interfaces Pin
DavidNohejl3-Jan-05 9:53
DavidNohejl3-Jan-05 9:53 
GeneralRe: Interfaces Pin
Bahadir Cambel3-Jan-05 11:52
Bahadir Cambel3-Jan-05 11:52 
GeneralRe: Interfaces Pin
DavidNohejl3-Jan-05 12:30
DavidNohejl3-Jan-05 12:30 
GeneralRe: Interfaces Pin
Bahadir Cambel3-Jan-05 14:27
Bahadir Cambel3-Jan-05 14:27 
GeneralRe: Interfaces Pin
DavidNohejl3-Jan-05 14:50
DavidNohejl3-Jan-05 14:50 
GeneralRe: Interfaces Pin
jan larsen3-Jan-05 20:17
jan larsen3-Jan-05 20:17 
GeneralRe: Interfaces Pin
DavidNohejl3-Jan-05 23:56
DavidNohejl3-Jan-05 23:56 
GeneralRe: Interfaces Pin
jan larsen4-Jan-05 0:48
jan larsen4-Jan-05 0:48 
GeneralRe: Interfaces Pin
DavidNohejl4-Jan-05 1:35
DavidNohejl4-Jan-05 1:35 
Generalabout the xmltextreader Pin
dhol2-Jan-05 19:29
dhol2-Jan-05 19:29 
GeneralRe: about the xmltextreader Pin
DavidNohejl3-Jan-05 9:35
DavidNohejl3-Jan-05 9:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.