473,320 Members | 1,804 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,320 software developers and data experts.

Urgent pls


I'm running this code to open a stream as pdf file:
Response.ContentType = "application/pdf";
try
{ mystream = someStream....;
byte[] myfile = mystream.ReadBytes((int)someStreamLenght);
myfile.Length.ToString();
Response.BinaryWrite(myfile);
}
finally
{
Response.Flush();
Response.Close();
mystream.Close();
}
but I run it in a 3 different machines it's telling me that the file is
corrupt or damaged.
and when running it in different machine that have the latest Acrobat 8.0
the document is opening fine!!!?
is this an issue with ASP? because I running VS 2005.

Cheers.

Jan 16 '07 #1
4 1066
is this an issue with ASP? because I running VS 2005.
No: your code.

OK, I doubt that your code really looks like that, as ReadBytes
doesn't normally take that signature... the problem is probably that
you are truncating the file; ReadBytes is only guaranteed to return
"some" data (or an EOF) - not "all" - and if you have undersized your
buffer you will get other problems.

The trick is to loop - something like:

public static long CopyStream(System.IO.Stream source,
System.IO.Stream destination) {
const int BUFFER_SIZE = 512;
long copied = 0;
byte[] buffer = new byte[BUFFER_SIZE];
int bytes;
while ((bytes = source.Read(buffer, 0, BUFFER_SIZE)) 0)
{
destination.Write(buffer, 0, bytes);
copied += bytes;
}
destination.Flush(); // optional step
return copied;
}

Then call:

// capture result if you want to know the *real* length
CopyStream(someStream, Response.OutputStream);

(and close the response etc)

that do ya?

Marc
Jan 16 '07 #2
Sounds like you need Acrobat 8 to make it work, i presume the file is an
acrobat 8 file or something? Try using a file that uses earlier versions of
acrobat and see what results you get. It may be that it needs acrobat or
some assemblies for it? I have nevr done what your attempting so that's the
best advice i can give.

"Badis" <Ba***@discussions.microsoft.comwrote in message
news:67**********************************@microsof t.com...
>
I'm running this code to open a stream as pdf file:
Response.ContentType = "application/pdf";
try
{ mystream = someStream....;
byte[] myfile = mystream.ReadBytes((int)someStreamLenght);
myfile.Length.ToString();
Response.BinaryWrite(myfile);
}
finally
{
Response.Flush();
Response.Close();
mystream.Close();
}
but I run it in a 3 different machines it's telling me that the file is
corrupt or damaged.
and when running it in different machine that have the latest Acrobat 8.0
the document is opening fine!!!?
is this an issue with ASP? because I running VS 2005.

Cheers.

Jan 16 '07 #3
Have realised you are using BinaryReader, not (as name implied)
Stream; highlights that it is useful to see the *actual* code (i.e.
with variable declarations, and just the irrelevant bits snipped).

It is *possible* that Acrobat 8.0 is needed, but I think that it is
more likely that Acrobat 8.0 is just being more forgiving with
incorrectly terminated files or header / body size mismatches. Try
opening the file (directly off the file system, not via the web) on
one of the "broken" machines (i.e. not Acrobat 8.0). If it opens, then
it is your code. If it still doesn't open then either it needs 8.0,
else the file is genuinely knackered.

Aside: where possible, avoid big buffers; for a complex PDF with lots
of images etc this could consume buckets of memory and isn't very
scalable. The stream-based (small buffer) operations are far more
efficient. You can of course tweak BUFFER_SIZE to suit your scenario.

Marc
Jan 16 '07 #4
I'm running this code to open a stream as pdf file:
Response.ContentType = "application/pdf";
try
{ mystream = someStream....;
byte[] myfile = mystream.ReadBytes((int)someStreamLenght);
myfile.Length.ToString();
Response.BinaryWrite(myfile);
}
finally
{
Response.Flush();
Response.Close();
mystream.Close();
}
but I run it in a 3 different machines it's telling me that the file is
corrupt or damaged.
and when running it in different machine that have the latest Acrobat 8.0
the document is opening fine!!!?
is this an issue with ASP? because I running VS 2005.

Cheers.
By the way, if that PDF really lives as a file on your server, there is
also Response.WriteFile(..).

Hans Kesting
Jan 16 '07 #5

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

Similar topics

3
by: Rob | last post by:
I have a form - when you click the submit button, it appends a variable to the URL (e.g. xyz.cgi?inputID=some_dynamic_variable) It also opens a new page. Now, that some_dynamic_variable is...
9
by: Stefan Bauer | last post by:
Hi NG, we've got a very urgent problem... :( We are importing data with the LOAD utility. The input DATE field data is in the format DDMMYYYY (for days) and MMYYYY (for months). The target...
8
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
28
by: Tamir Khason | last post by:
Follwing the struct: public struct TpSomeMsgRep { public uint SomeId;
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
7
by: zeyais | last post by:
Here is my HTML: <style> ..leftcolumn{float:left;width:300px;border: 1px solid #ccc} ..rtcolumn{float:left;width:600px;border: 1px solid #ccc} </style> <body> <div class="leftcolumn"...
33
by: dembla | last post by:
Hey Frnds can anyone help me in this i need a program in 'c' PROGRAM to print NxN Matrix 9 1 8 1 2 3 2 7 3 as 4 5 6 6 4 5 7 8 9 in sorted form
8
by: ginnisharma1 | last post by:
Hi All, I am very new to C language and I got really big assignment in my work.I am wondering if anyone can help me.........I need to port compiler from unix to windows and compiler is written...
3
by: N. Spiker | last post by:
I am attempting to receive a single TCP packet with some text ending with carriage return and line feed characters. When the text is send and the packet has the urgent flag set, the text read from...
7
by: Cirene | last post by:
I used to use the Web Deployment Project with my VS2005 projects. Now I've fully upgraded to VS2008. Do I have to download a new version of the Web Deployment Project? If so where can I find...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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...
0
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.