Click here to Skip to main content
16,012,468 members
Home / Discussions / C#
   

C#

 
AnswerRe: What Class(es) to use for Hardware Profiling? Pin
Abhinav S23-Nov-10 17:48
Abhinav S23-Nov-10 17:48 
QuestionConvert Word doc to Byte Pin
MWRivera23-Nov-10 8:21
MWRivera23-Nov-10 8:21 
AnswerRe: Convert Word doc to Byte Pin
Luc Pattyn23-Nov-10 8:34
sitebuilderLuc Pattyn23-Nov-10 8:34 
GeneralRe: Convert Word doc to Byte Pin
MWRivera23-Nov-10 9:16
MWRivera23-Nov-10 9:16 
GeneralRe: Convert Word doc to Byte Pin
Luc Pattyn23-Nov-10 9:24
sitebuilderLuc Pattyn23-Nov-10 9:24 
GeneralRe: Convert Word doc to Byte Pin
MWRivera23-Nov-10 9:45
MWRivera23-Nov-10 9:45 
GeneralRe: Convert Word doc to Byte Pin
Luc Pattyn23-Nov-10 10:34
sitebuilderLuc Pattyn23-Nov-10 10:34 
AnswerRe: Convert Word doc to Byte Pin
NickHighIQ23-Nov-10 13:51
NickHighIQ23-Nov-10 13:51 
Base64 is a number system - normal numbers like 1, 2, 3 are decimal or Base10, binary is Base2 etc.

Byte[] b = Convert.FromBase64String(attach.Body);


This would make sense IF "attach.Body" was in fact a Base64 string. Base64 still confuses me dude, so don't let Luc Pattyn make you feel bad for not being born with the intrinsic knowledge of Base64 and its use, as he must have been in order to provide him the right to speak to someone like that (I think a swing at his demeaning tone is fair enough, don't you Wink | ;) ).

What type is the attach.Body property, is it a just a basic System.String? If you want to convert a string into a byte array, there are plenty of ways to do it, and it's something that comes up often (and I can NEVER remember how to do it). It also depends on the type of encoding you want.

In the System.Text namespace there are several Encoding classes: I usually use ASCIIEncoding:

string myText = "Hello world!";
ASCIIEncoding enc = new ASCIIEncoding();
byte[] dataBuffer = enc.GetBytes(myText);


There is also the UTF8Encoding class I can think of off the top of my head. The type of encoding you use does matter!


Having said all this, it seems like you're doing something odd. Can you explain to me what your actual intention is with "converting the html formatted word document into a Byte array"? What do you want to do that for? And then you said later that you wanted to save these files out to a directory. If I was you, I would do something like this:

using (var fileStream = new FileStream("theNewFileName.txt", FileMode.Create)
{
    using (var streamWriter = new StreamWriter(fileStream)
    {
        streamWriter.Write(attach.Body);
    }
}


Using the StreamWriter class, you can interact at a higher level and use strings rather than byte arrays - much clearer and simpler code IMHO.

Does this help?
GeneralRe: Convert Word doc to Byte Pin
Luc Pattyn23-Nov-10 14:41
sitebuilderLuc Pattyn23-Nov-10 14:41 
GeneralRe: Convert Word doc to Byte Pin
NickHighIQ23-Nov-10 15:53
NickHighIQ23-Nov-10 15:53 
GeneralRe: Convert Word doc to Byte Pin
Pete O'Hanlon23-Nov-10 23:13
mvePete O'Hanlon23-Nov-10 23:13 
GeneralRe: Convert Word doc to Byte Pin
NickHighIQ24-Nov-10 1:10
NickHighIQ24-Nov-10 1:10 
GeneralRe: Convert Word doc to Byte Pin
Luc Pattyn24-Nov-10 3:42
sitebuilderLuc Pattyn24-Nov-10 3:42 
GeneralRe: Convert Word doc to Byte Pin
MWRivera24-Nov-10 4:59
MWRivera24-Nov-10 4:59 
GeneralRe: Convert Word doc to Byte Pin
MWRivera24-Nov-10 5:01
MWRivera24-Nov-10 5:01 
GeneralRe: Convert Word doc to Byte Pin
MWRivera30-Nov-10 5:05
MWRivera30-Nov-10 5:05 
QuestionGeneric Event In Interface Pin
Kevin Marois23-Nov-10 6:10
professionalKevin Marois23-Nov-10 6:10 
AnswerRe: Generic Event In Interface Pin
Keith Barrow23-Nov-10 6:25
professionalKeith Barrow23-Nov-10 6:25 
QuestionProgrammatically checking DataGridViewCheckBoxCell Pin
kapax523-Nov-10 4:34
kapax523-Nov-10 4:34 
AnswerRe: Programmatically checking DataGridViewCheckBoxCell Pin
Dave Kreskowiak23-Nov-10 6:25
mveDave Kreskowiak23-Nov-10 6:25 
Questionhow to return? Pin
Jassim Rahma23-Nov-10 4:12
Jassim Rahma23-Nov-10 4:12 
AnswerStill not a C# question Pin
Pete O'Hanlon23-Nov-10 4:22
mvePete O'Hanlon23-Nov-10 4:22 
AnswerRe: how to return? Pin
Dave Kreskowiak23-Nov-10 4:30
mveDave Kreskowiak23-Nov-10 4:30 
AnswerRe: how to return? Pin
Keith Barrow23-Nov-10 6:28
professionalKeith Barrow23-Nov-10 6:28 
AnswerRe: how to return? Pin
Smithers-Jones23-Nov-10 6:40
Smithers-Jones23-Nov-10 6:40 

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.