Click here to Skip to main content
15,885,931 members
Home / Discussions / C#
   

C#

 
GeneralRe: Reading and writing USB HID FeatureReports async. Pin
Jason Gleim10-Feb-14 10:38
professionalJason Gleim10-Feb-14 10:38 
AnswerRe: Reading and writing USB HID FeatureReports async. Pin
Bernhard Hiller10-Feb-14 21:21
Bernhard Hiller10-Feb-14 21:21 
QuestionSOAP from scratch? Pin
Antessima10-Feb-14 4:41
Antessima10-Feb-14 4:41 
AnswerRe: SOAP from scratch? Pin
jschell10-Feb-14 8:11
jschell10-Feb-14 8:11 
GeneralRe: SOAP from scratch? Pin
Antessima10-Feb-14 8:42
Antessima10-Feb-14 8:42 
GeneralRe: SOAP from scratch? Pin
jschell11-Feb-14 11:04
jschell11-Feb-14 11:04 
QuestionReadAllBytes Method of the File Class PROBLEM Pin
computerpublic10-Feb-14 4:39
computerpublic10-Feb-14 4:39 
AnswerRe: ReadAllBytes Method of the File Class PROBLEM Pin
Richard Deeming10-Feb-14 5:30
mveRichard Deeming10-Feb-14 5:30 
computerpublic wrote:
//the code works great up to this point

Well, it runs, but it might not be doing what you think it's doing. You're displaying the length of the last file in the directory, but your loop and variable name suggest you want to display the total length of all files in the directory. That's quite a simple change:
C#
foreach (FileInfo ap in Arr)
    Totbyte += ap.Length;

Note the "+=" instead of just "=".


computerpublic wrote:
//want to set up an array for the exact file length above and read all bytes into the array

Firstly, what would the length of the files in C:\Folder have to do with the length of a temporary file?

Secondly, the ReadAllBytes method will return an array of the correct size to contain all of the bytes in the file you're reading. You don't need to specify the size of the array.
C#
byte[] data = File.ReadAllBytes(tempPath);


Thirdly, since you're just copying one file to another, why not simple use the File.Copy method?
C#
if (File.Exists(temPath))
{
    File.Copy(temPath, temPath2, true);
}


Finally, look at the documentation of GetTempFileName:
Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file.

That means that temPath will always exist, and will be an empty file. Copying it over another empty file will have no effect.


Perhaps if you explain what you're trying to do, we might be able to point you in the right direction. Smile | :)



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: ReadAllBytes Method of the File Class PROBLEM Pin
computerpublic10-Feb-14 5:45
computerpublic10-Feb-14 5:45 
GeneralRe: ReadAllBytes Method of the File Class PROBLEM Pin
Richard Deeming10-Feb-14 5:56
mveRichard Deeming10-Feb-14 5:56 
GeneralRe: ReadAllBytes Method of the File Class PROBLEM Pin
computerpublic10-Feb-14 6:27
computerpublic10-Feb-14 6:27 
GeneralRe: ReadAllBytes Method of the File Class PROBLEM Pin
Richard Deeming10-Feb-14 6:54
mveRichard Deeming10-Feb-14 6:54 
AnswerRe: ReadAllBytes Method of the File Class PROBLEM Pin
Matt T Heffron10-Feb-14 7:47
professionalMatt T Heffron10-Feb-14 7:47 
GeneralRe: ReadAllBytes Method of the File Class PROBLEM Pin
BillWoodruff10-Feb-14 21:23
professionalBillWoodruff10-Feb-14 21:23 
AnswerRe: ReadAllBytes Method of the File Class PROBLEM Pin
BillWoodruff10-Feb-14 6:37
professionalBillWoodruff10-Feb-14 6:37 
GeneralRe: ReadAllBytes Method of the File Class PROBLEM Pin
computerpublic10-Feb-14 6:51
computerpublic10-Feb-14 6:51 
GeneralRe: ReadAllBytes Method of the File Class PROBLEM Pin
Dave Kreskowiak10-Feb-14 7:14
mveDave Kreskowiak10-Feb-14 7:14 
GeneralRe: ReadAllBytes Method of the File Class PROBLEM Pin
Matt T Heffron10-Feb-14 7:49
professionalMatt T Heffron10-Feb-14 7:49 
QuestionLock Controls or Record for Add/Edit/Delete C# Pin
ahmed_one9-Feb-14 22:59
ahmed_one9-Feb-14 22:59 
AnswerRe: Lock Controls or Record for Add/Edit/Delete C# Pin
Keith Barrow10-Feb-14 1:04
professionalKeith Barrow10-Feb-14 1:04 
GeneralRe: Lock Controls or Record for Add/Edit/Delete C# Pin
ahmed_one10-Feb-14 1:13
ahmed_one10-Feb-14 1:13 
GeneralRe: Lock Controls or Record for Add/Edit/Delete C# Pin
Keith Barrow10-Feb-14 1:54
professionalKeith Barrow10-Feb-14 1:54 
GeneralRe: Lock Controls or Record for Add/Edit/Delete C# Pin
ahmed_one10-Feb-14 2:36
ahmed_one10-Feb-14 2:36 
GeneralRe: Lock Controls or Record for Add/Edit/Delete C# Pin
Eddy Vluggen11-Feb-14 8:20
professionalEddy Vluggen11-Feb-14 8:20 
GeneralRe: Lock Controls or Record for Add/Edit/Delete C# Pin
ahmed_one11-Feb-14 17:21
ahmed_one11-Feb-14 17:21 

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.