473,396 Members | 2,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

File Encoding Styles

Hi,
I am downloading a GIF file(as a mail attachement) with this file
format, Content-Transfer-Encoding: base64;

Now I am writing the downloaded data to a file with this technique:

streamWriter = new StreamWriter(@startupPath+"\\"+filename, false);
streamWriter.WriteLine(data);

I am not specifying any file Encoding. When I try to open the file
just created with Microsoft Photo Editor, the following error is
given: "Can't determine type.";

I have tried this technique with different file formats, but it worked
only for text-files.

Can someone give some help on how to solve this problem.
Thanks in Advance
Nov 17 '05 #1
8 7548
Hi,

First of all, you need to decode the incoming base64 stream to get the
actual GIF file bytes.
Once you get the byte array, you will need to use the BinaryWriter class and
its Write method to write out the resultant array to a file.

A tip for recognizing whether the byte array is actually a GIF file - it
should contain the 'GIF89a' signature (can also be 'GIF87' but that one is
really rare) somewhere in the beginning.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Xarky" <be*********@yahoo.com> wrote in message
news:bc*************************@posting.google.co m...
Hi,
I am downloading a GIF file(as a mail attachement) with this file
format, Content-Transfer-Encoding: base64;

Now I am writing the downloaded data to a file with this technique:

streamWriter = new StreamWriter(@startupPath+"\\"+filename, false);
streamWriter.WriteLine(data);

I am not specifying any file Encoding. When I try to open the file
just created with Microsoft Photo Editor, the following error is
given: "Can't determine type.";

I have tried this technique with different file formats, but it worked
only for text-files.

Can someone give some help on how to solve this problem.
Thanks in Advance


Nov 17 '05 #2
Hi,

How should I decode the incoming data to bytes.

Can you please give me some futher help or recommend me some links.

Thanks in Advance

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3
On Thu, 14 Apr 2005 13:22:33 +0300, Dmytro Lapshyn [MVP]
<x-****@no-spam-please.hotpop.com> wrote:
Hi,

First of all, you need to decode the incoming base64 stream to get the
actual GIF file bytes.
Once you get the byte array, you will need to use the BinaryWriter class
and its Write method to write out the resultant array to a file.

A tip for recognizing whether the byte array is actually a GIF file - it
should contain the 'GIF89a' signature (can also be 'GIF87' but that one
is really rare) somewhere in the beginning.


Yep, the first three bytes in a gif file is always "GIF" and the following
three bytes is the version number and can be "89a" or "87a".

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #4
Dmytro Lapshyn [MVP] <x-****@no-spam-please.hotpop.com> wrote:
First of all, you need to decode the incoming base64 stream to get the
actual GIF file bytes.
Once you get the byte array, you will need to use the BinaryWriter class and
its Write method to write out the resultant array to a file.


Note that there's no real reason to use BinaryWriter here - a straight
stream would do everything required.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #5
xarky d_best <be*********@yahoo.com> wrote:
How should I decode the incoming data to bytes.


The easiest thing would be to use Convert.FromBase64String on the
returned text data.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6
Hi,
After doing some debugging I kept track for the following information:

Text File:
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
This worked perfectly with writing the data being read with a
streamwriter.

GIF:
Content-Type: image/gif
Content-Transfer-Encoding: base64
As suggested converted to base64 and used BinaryWriter, and worked
perfect

Excel:
Content-Type: application/vnd.ms-excel
Content-Transfer-Encoding: base64
As suggested converted to base64 and used BinaryWriter, and worked
perfect

MP3:
Content-Type: audio/mpeg
Content-Transfer-Encoding: base64
As suggested converted to base64 and used BinaryWriter, and worked
perfect

PDF:
Content-Type: application/pdf
Content-Transfer-Encoding: quoted-printable
Tried in both ways (like Text-files, and MP3/GIF/etc) both this file
didn't work and gave an error when tried to open file.
Error given is the following: "There was an error opening this document.
The file is damaged and could not be repaired"

Then I tried another PDF file:
Content-Type: application/pdf
Content-Transfer-Encoding: base64
As suggested converted to base64 and used BinaryWriter, and worked
perfect.

What could the problem be. Could it be that the pdf file is corrupted,
though the original file opens perfectly.

Can someone help me out.
Thanks in Advance

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #7
Hi,

Pay attention to this header:

Content-Transfer-Encoding: quoted-printable

It is NOT base64, nor these are plain bytes. This is yet another type of
encoding, please search the Web for its specifics.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"xarky d_best" <be*********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi,
After doing some debugging I kept track for the following information:

Text File:
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
This worked perfectly with writing the data being read with a
streamwriter.

GIF:
Content-Type: image/gif
Content-Transfer-Encoding: base64
As suggested converted to base64 and used BinaryWriter, and worked
perfect

Excel:
Content-Type: application/vnd.ms-excel
Content-Transfer-Encoding: base64
As suggested converted to base64 and used BinaryWriter, and worked
perfect

MP3:
Content-Type: audio/mpeg
Content-Transfer-Encoding: base64
As suggested converted to base64 and used BinaryWriter, and worked
perfect

PDF:
Content-Type: application/pdf
Content-Transfer-Encoding: quoted-printable
Tried in both ways (like Text-files, and MP3/GIF/etc) both this file
didn't work and gave an error when tried to open file.
Error given is the following: "There was an error opening this document.
The file is damaged and could not be repaired"

Then I tried another PDF file:
Content-Type: application/pdf
Content-Transfer-Encoding: base64
As suggested converted to base64 and used BinaryWriter, and worked
perfect.

What could the problem be. Could it be that the pdf file is corrupted,
though the original file opens perfectly.

Can someone help me out.
Thanks in Advance

*** Sent via Developersdex http://www.developersdex.com ***


Nov 17 '05 #8
Hi,
I am trying searching on the web on how to encode and how to write
"quoted-printable" data.

Can some help be provided, because I can't find anything useful.

Thanks in Advance.


*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a...
4
by: Alexander Bolotnov | last post by:
I am trying to read xhtml spec and use one of its examples about css2 in xhtml. The example on the PDF paper with internal styles defenition works just fine. When I try to use an external file...
0
by: | last post by:
hi, I have aspx web project. I added reference to J# project dll. In J# project i have link towords file on IIS server (aspx project) File link code in J# (java) are below: public static void...
12
by: Brian Henry | last post by:
first question... I have a flat file which unfortinuatly has columns seperated by nulls instead of spaces (a higher up company created it this way for us) is there anyway to do a readline with this...
3
by: Chip | last post by:
There is surprisingly little information on the various encoding options for reading a text file. I have what seems to be a very basic issue: I'm reading a text file that includes Spanish...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
1
by: ujjwaltrivedi | last post by:
Hey guys, Can anyone tell me how to create a text file with Unicode Encoding. In am using FileStream Finalfile = new FileStream("finalfile.txt", FileMode.Append, FileAccess.Write); ...
14
by: Ashutosh Bhawasinka | last post by:
Hi, How can I retrieve the system icon associated with a file/folder so that I can show it in the list view adjacent to the file/folder name? Regards, Ashutosh Bhawasinka
0
by: sangam56 | last post by:
Hi all. I have successfully written xsl code to transform xml to excel file. I have also used css styles for excel using <ss:Styles>...</ss:Styles> inline in the xsl file. My requirement is write...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.