473,766 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(@s tartupPath+"\\" +filename, false);
streamWriter.Wr iteLine(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 7584
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*********@ya hoo.com> wrote in message
news:bc******** *************** **@posting.goog le.com...
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(@s tartupPath+"\\" +filename, false);
streamWriter.Wr iteLine(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.c om> 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.c om> 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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #5
xarky d_best <be*********@ya hoo.com> wrote:
How should I decode the incoming data to bytes.


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

--
Jon Skeet - <sk***@pobox.co m>
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*********@ya hoo.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.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
7773
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 DB and display it onscreen. No matter which way I open the file, convert it to Unicode/leave it as is or what ever, I see all single bytes ok, but double bytes become 2 seperate single bytes. Surely there is an easy way to convert these mixed...
4
4126
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 with css defs it just does not work unless I use <link rel...> in the <header>. However, this is not how the xhtml examples link style sheets and I would like to know the reason why it is not working for me. Here is the html file:
0
1098
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 Pdf() { try { //Setup directories File baseDir = new File("."); File outDir = new File(baseDir, "TestPages"); outDir.mkdirs();
12
2989
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 and not have it affected by the null? because it is right now causes truncated data at wierd places... but as soon as i manually with a hex editor change char(00) to char(20) in the files it reads prerfectly... which leads me to my 2nd...
3
5126
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 characters such as "ñ". When I read the file into a string, that character is missing. Encoding seems to be the culprit. File writers SHOULD begin a file with the BOM (Byte Order Mark) to let us know what encoding to read the file with, but most software...
1
6508
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" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
1
32947
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); ###Question: Now this creates finalfile.txt with ANSI Encoding ...which is a default. Either tell me how to change the default or how to create a
14
12798
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
2057
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 the css styles in separate file and use it with the excel file. Apparently two approaches: 1. Inject style code in generated xls file. -- OR -- 2. Reference style file from outside in the generated xls file.
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10168
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10008
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.