By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,795 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,795 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.