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

N

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
 
N

Nicholas Paldino [.NET/C# MVP]

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]
- (e-mail address removed)

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
 
I

Ignacio Machin \( .NET/ C# MVP \)

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


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
 
N

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
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


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
 
N

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top