Click here to Skip to main content
15,890,825 members
Home / Discussions / C#
   

C#

 
QuestionAsymetric Cryptography Problem Pin
unforgiven_wild_rose5-Aug-07 5:11
unforgiven_wild_rose5-Aug-07 5:11 
AnswerRe: Asymetric Cryptography Problem Pin
Hessam Jalali5-Aug-07 6:27
Hessam Jalali5-Aug-07 6:27 
GeneralRe: Asymetric Cryptography Problem Pin
unforgiven_wild_rose5-Aug-07 20:50
unforgiven_wild_rose5-Aug-07 20:50 
GeneralRe: Asymetric Cryptography Problem Pin
Hessam Jalali6-Aug-07 1:02
Hessam Jalali6-Aug-07 1:02 
GeneralRe: Asymetric Cryptography Problem Pin
unforgiven_wild_rose6-Aug-07 23:52
unforgiven_wild_rose6-Aug-07 23:52 
QuestionComboBox In DataGridView Pin
Thaer Hamael5-Aug-07 4:21
Thaer Hamael5-Aug-07 4:21 
QuestionTry to use C# code in C++ code as com instance ... Pin
Yanshof5-Aug-07 1:56
Yanshof5-Aug-07 1:56 
QuestionReading file as binary. Success. But...... Pin
Life as a Coder5-Aug-07 1:12
Life as a Coder5-Aug-07 1:12 
Thanks for the answear before. I manage to cr8 app to open file as binary, and success.
but..... sometimes it can't read the whole content

This is my code :
<my code><br />
public byte[] readBin(string FILE_NAME)<br />
        {<br />
            // Create the reader for data.<br />
            FileStream fs = new FileStream(FILE_NAME, FileMode.Open, FileAccess.Read);<br />
            BinaryReader r = new BinaryReader(fs);<br />
            // Read data from Test.data.<br />
            int FILE_LENGTH = (int)fs.Length;<br />
            int i = 0;<br />
            byte[] output = new byte[FILE_LENGTH];<br />
            sbyte read;<br />
            try<br />
            {<br />
                while (r.PeekChar() != -1)<br />
                {<br />
                    read = r.ReadSByte();<br />
                    output[i++] = (byte)read;<br />
                }<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                MessageBox.Show(ex.ToString());<br />
            }<br />
<br />
            r.Close();<br />
            fs.Close();<br />
            return (output);<br />
        }<br />
</end of code>


It really can read few file perfectly include the file that can't be opened correctly before. but sometimes it still miss a part of file. eg:
a file contain binary like this (opened by UltraEdit32)
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F<br />
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F<br />
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F<br />
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F<br />
40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F<br />
50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F<br />
60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F<br />
70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F<br />
80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F<br />
90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F<br />
A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF<br />
B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF<br />
C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF<br />
D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF<br />
E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF<br />
F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF


My code only manage to read
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F<br />
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F<br />
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F<br />
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F<br />
40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F<br />
50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F<br />
60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F<br />
70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F


And sometimes it throw an exception like this when open some file.
<small>System.ArgumentException: The output char buffer is too small to contain the decoded characters, encoding 'Unicode (UTF-8)' fallback 'System.Text.DecoderReplacementFallback'.<br />
Parameter name: chars<br />
   at System.Text.Encoding.ThrowCharsOverflow()<br />
   at System.Text.Encoding.ThrowCharsOverflow(DecoderNLS decoder, Boolean nothingDecoded)<br />
   at System.Text.UTF8Encoding.GetChars(Byte* bytes, Int32 byteCount, Char* chars, Int32 charCount, DecoderNLS baseDecoder)<br />
   at System.Text.DecoderNLS.GetChars(Byte* bytes, Int32 byteCount, Char* chars, Int32 charCount, Boolean flush)<br />
   at System.Text.DecoderNLS.GetChars(Byte[] bytes, Int32 byteIndex, Int32 byteCount, Char[] chars, Int32 charIndex, Boolean flush)<br />
   at System.Text.DecoderNLS.GetChars(Byte[] bytes, Int32 byteIndex, Int32 byteCount, Char[] chars, Int32 charIndex)<br />
   at System.IO.BinaryReader.InternalReadOneChar()<br />
   at System.IO.BinaryReader.Read()<br />
   at System.IO.BinaryReader.PeekChar()<br />
   at ASCII_test.fileHandle.readBin(String FILE_NAME) in D:\Core Document\Programming\Microsoft Visual Studio 2005\ASCII test\ASCII test\fileHandle.cs:line 43</small><br />

Please someone help me. Smile | :)
Thanks before.



Training makes perfect....

AnswerRe: Reading file as binary. Success. But...... Pin
Colin Angus Mackay5-Aug-07 1:27
Colin Angus Mackay5-Aug-07 1:27 
NewsRe: Reading file as binary. Success. But...... Pin
Life as a Coder5-Aug-07 1:35
Life as a Coder5-Aug-07 1:35 
AnswerRe: Reading file as binary. Success. But...... Pin
Luc Pattyn5-Aug-07 1:56
sitebuilderLuc Pattyn5-Aug-07 1:56 
Questionhow to detetmine that sql was installed on computer or not ? Pin
hdv2125-Aug-07 1:05
hdv2125-Aug-07 1:05 
AnswerRe: how to detetmine that sql was installed on computer or not ? Pin
Developer6115-Aug-07 1:14
Developer6115-Aug-07 1:14 
GeneralRe: how to detetmine that sql was installed on computer or not ? Pin
Colin Angus Mackay5-Aug-07 1:24
Colin Angus Mackay5-Aug-07 1:24 
AnswerRe: how to detetmine that sql was installed on computer or not ? Pin
Colin Angus Mackay5-Aug-07 1:33
Colin Angus Mackay5-Aug-07 1:33 
AnswerRe: how to detetmine that sql was installed on computer or not ? Pin
Paul Conrad5-Aug-07 5:06
professionalPaul Conrad5-Aug-07 5:06 
QuestionCrystal Report working with generic collections Pin
Developer6114-Aug-07 22:44
Developer6114-Aug-07 22:44 
Questionwhat is exe of search option in win xp Pin
San@Coding4-Aug-07 22:11
San@Coding4-Aug-07 22:11 
AnswerRe: what is exe of search option in win xp Pin
Luc Pattyn4-Aug-07 23:56
sitebuilderLuc Pattyn4-Aug-07 23:56 
Questiondraw a box on screen Pin
hamid_m4-Aug-07 21:50
hamid_m4-Aug-07 21:50 
AnswerRe: draw a box on screen Pin
ArunkumarSundaravelu6-Aug-07 5:22
ArunkumarSundaravelu6-Aug-07 5:22 
QuestionProperties Window [modified] Pin
sniper474-Aug-07 21:22
sniper474-Aug-07 21:22 
AnswerRe: Properties Window Pin
Hessam Jalali4-Aug-07 22:36
Hessam Jalali4-Aug-07 22:36 
GeneralRe: Properties Window Pin
sniper475-Aug-07 0:31
sniper475-Aug-07 0:31 
GeneralRe: Properties Window Pin
J. Dunlap5-Aug-07 8:48
J. Dunlap5-Aug-07 8:48 

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.