473,324 Members | 2,356 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,324 software developers and data experts.

Can we really delete lines from a Binary File??? Is there any other solution??

Neo
Hello:
I am receiving a Binary File in a Request from a application. The
stream which comes to me has the boundary (Something like
"---------------------------39<WBR>*0C0F3E0099" without the quotes),
and also
some more text like this and file name (e.g. "Content-Disposition:
form-data; name="upload_file"; filename="C:\testing\myfile.da<WBR>*t"
Content-Type: application/octet-stream")
The binary content starts after "application/octet-stream".
The end of the file is also a boundary.
I need to filter this content and only write the binary content to the
disk.
I know the boundary string from the Request Headers and also the file
size. I am reading the request into a byte array using the following
code -
<code>
int iLength = (int) Request.InputStream.Length;
byte[] byBuffer = new byte[iLength];
Request.InputStream.Read(byBuf*fer,0,iLength);
</code>
Then i am using a filestream object to write the buffer to disk.
I dont know how to filter/replace the binary content. I tried to
convert it into a String object, but the file sizes are more than 2 MB,

and i dont want the string object to hold os much data.
Can someone please suggest any method of replacing some text in a
Binary content. I want to remove the boundary text from the stream.

I also tried writing the binary content to the disk and then reading it
line by line and writing only the needed content to another file using
streamreader and streamwriter, but i get a wierd error - "Found a low
surrogate char without a preceding high surrogate at index: 620. The
input may not be in this encoding, or may not contain valid Unicode
(UTF-16) characters. Parameter name: chars" - Exception

Does anyone know how to filter binary content? Thanks in advance for
all your help!!

Regards
Sunil Jambekar

Nov 17 '05 #1
5 5288
Sunil,

I am curious, why don't you just use ASP.NET? Is there are reason you
are parsing this yourself?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Neo" <su************@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hello:
I am receiving a Binary File in a Request from a application. The
stream which comes to me has the boundary (Something like
"---------------------------39<WBR>*0C0F3E0099" without the quotes),
and also
some more text like this and file name (e.g. "Content-Disposition:
form-data; name="upload_file"; filename="C:\testing\myfile.da<WBR>*t"
Content-Type: application/octet-stream")
The binary content starts after "application/octet-stream".
The end of the file is also a boundary.
I need to filter this content and only write the binary content to the
disk.
I know the boundary string from the Request Headers and also the file
size. I am reading the request into a byte array using the following
code -
<code>
int iLength = (int) Request.InputStream.Length;
byte[] byBuffer = new byte[iLength];
Request.InputStream.Read(byBuf*fer,0,iLength);
</code>
Then i am using a filestream object to write the buffer to disk.
I dont know how to filter/replace the binary content. I tried to
convert it into a String object, but the file sizes are more than 2 MB,

and i dont want the string object to hold os much data.
Can someone please suggest any method of replacing some text in a
Binary content. I want to remove the boundary text from the stream.

I also tried writing the binary content to the disk and then reading it
line by line and writing only the needed content to another file using
streamreader and streamwriter, but i get a wierd error - "Found a low
surrogate char without a preceding high surrogate at index: 620. The
input may not be in this encoding, or may not contain valid Unicode
(UTF-16) characters. Parameter name: chars" - Exception

Does anyone know how to filter binary content? Thanks in advance for
all your help!!

Regards
Sunil Jambekar
Nov 17 '05 #2
hi,

You should give more details about your environment, is this a file being
uploaded? if so use ASp.NET support for it.

Or maybe is a binary file you are getting, in this case you should just use
either BinaryRead or InputStream.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Neo" <su************@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hello:
I am receiving a Binary File in a Request from a application. The
stream which comes to me has the boundary (Something like
"---------------------------39<WBR>*0C0F3E0099" without the quotes),
and also
some more text like this and file name (e.g. "Content-Disposition:
form-data; name="upload_file"; filename="C:\testing\myfile.da<WBR>*t"
Content-Type: application/octet-stream")
The binary content starts after "application/octet-stream".
The end of the file is also a boundary.
I need to filter this content and only write the binary content to the
disk.
I know the boundary string from the Request Headers and also the file
size. I am reading the request into a byte array using the following
code -
<code>
int iLength = (int) Request.InputStream.Length;
byte[] byBuffer = new byte[iLength];
Request.InputStream.Read(byBuf*fer,0,iLength);
</code>
Then i am using a filestream object to write the buffer to disk.
I dont know how to filter/replace the binary content. I tried to
convert it into a String object, but the file sizes are more than 2 MB,

and i dont want the string object to hold os much data.
Can someone please suggest any method of replacing some text in a
Binary content. I want to remove the boundary text from the stream.

I also tried writing the binary content to the disk and then reading it
line by line and writing only the needed content to another file using
streamreader and streamwriter, but i get a wierd error - "Found a low
surrogate char without a preceding high surrogate at index: 620. The
input may not be in this encoding, or may not contain valid Unicode
(UTF-16) characters. Parameter name: chars" - Exception

Does anyone know how to filter binary content? Thanks in advance for
all your help!!

Regards
Sunil Jambekar
Nov 17 '05 #3
Neo
Thanks Ignacio and Nick,

The details are as follows. There is a desktop application in MFC, and
i am building a web interface for that application in ASP.NET. I have
to upload a file from the C++ Application to ASP.NET web application.

I am using Multipart/form-data to transfer the file, as sending it as a
HTTP request in synchronous mode hangs my C++ application. What is
happening is that i am receiving the file on the server which i am
storing to the disk using request.inputstream.

What happens is that the boundary and the Content-Disposition :
application/octet-stream comes in the binary inputstream which i am
trying to filter. What i did was that i saved the file on the server
and then read it line by line using streamreader and streamwriter, but
it gives me some encoding problem.

So i am looking at ... can a file be uploaded from C++ Desktop
application to a ASP.NET web server application without the junk
content in the stream, i.e. only the file (complete as it was sent), or
is there any way to parse binary data??

All help is appreciated ... thanks for the same.

Regards

Sunil

Ignacio Machin ( .NET/ C# MVP ) wrote:
hi,

You should give more details about your environment, is this a file being
uploaded? if so use ASp.NET support for it.

Or maybe is a binary file you are getting, in this case you should just use
either BinaryRead or InputStream.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Neo" <su************@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hello:
I am receiving a Binary File in a Request from a application. The
stream which comes to me has the boundary (Something like
"---------------------------39<WBR>*0C0F3E0099" without the quotes),
and also
some more text like this and file name (e.g. "Content-Disposition:
form-data; name="upload_file"; filename="C:\testing\myfile.da<WBR>*t"
Content-Type: application/octet-stream")
The binary content starts after "application/octet-stream".
The end of the file is also a boundary.
I need to filter this content and only write the binary content to the
disk.
I know the boundary string from the Request Headers and also the file
size. I am reading the request into a byte array using the following
code -
<code>
int iLength = (int) Request.InputStream.Length;
byte[] byBuffer = new byte[iLength];
Request.InputStream.Read(byBuf*fer,0,iLength);
</code>
Then i am using a filestream object to write the buffer to disk.
I dont know how to filter/replace the binary content. I tried to
convert it into a String object, but the file sizes are more than 2 MB,

and i dont want the string object to hold os much data.
Can someone please suggest any method of replacing some text in a
Binary content. I want to remove the boundary text from the stream.

I also tried writing the binary content to the disk and then reading it
line by line and writing only the needed content to another file using
streamreader and streamwriter, but i get a wierd error - "Found a low
surrogate char without a preceding high surrogate at index: 620. The
input may not be in this encoding, or may not contain valid Unicode
(UTF-16) characters. Parameter name: chars" - Exception

Does anyone know how to filter binary content? Thanks in advance for
all your help!!

Regards


Sunil Jambekar


Nov 17 '05 #4
Neo
Hello All,

My problem got solved by changing some code on the C++ end and using
Request.Files.Get(0)

Thanks all for your help :)

Regards

Sunil Jambekar

Nov 17 '05 #5
ok,

good to know you nail it :)

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Neo" <su************@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hello All,

My problem got solved by changing some code on the C++ end and using
Request.Files.Get(0)

Thanks all for your help :)

Regards

Sunil Jambekar

Nov 17 '05 #6

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

Similar topics

7
by: Srinivasa T.N. | last post by:
Hi, I want to delete the first 3 lines and last 3 lines of a file. How can I do it? I want to repeat on multiple files.. TIA Regards, Seenu.
21
by: Hattuari | last post by:
I'm learning C++ after having spent several years in the computer industry doing both system administration and engineering. I've written code in Perl, Bash, Pascal, Ada, C, Mathematica (hundreds...
11
by: Jonan | last post by:
Hello, For several reasons I want to replace the built-in memory management with some custom built. The mem management itlsef is not subject to my question - it's ok to the point that I have...
9
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the...
15
by: batman | last post by:
i have a text file that is like: date = OCT0606 asdf sdaf asdfasdgsdgh asdfsdfasdg START-OF-DATA asdfasdfg asdfgdfgsfg
7
by: peraklo | last post by:
Hello, there is another problem i am facing. i have a text file which is about 15000 lines big. i have to cut the last 27 lines from that file and create a new text file that contans those 27...
1
by: shivapadma | last post by:
hello, can we do the below steps to delete a line from a file in c 1:first the lines in the files other than the desired line which has to be deleted are copied to the other...
10
by: Joah Senegal | last post by:
Hello all, I want something that should be realy really simple.... but I dont get it.. searched google and stuf, but found nothing useful. I;m opening a txt-file with a fstream. Now I want to...
18
by: Coffee Pot | last post by:
Thanks for any advice. ~ CP
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.