Click here to Skip to main content
15,880,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im using a web service method that return an byte[] (in this case a pdf)
here is my code:

wsDMS.TopMediaWebSession webService = new wsDMS.TopMediaWebSession();

idSession = webService.Login(username, password, language);

byte[] fileStream = webService.RetrieveFile(idSession, documentType, documentID, out extension);


File.WriteAllBytes(@"pathFile", fileStream);


I need to open that pdf on my client app, but with this code, when i try to open that file, i get this:
"adobe reader could not open because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)."

First you need to undestand the actions which take place at server and client side.

What you are doing in your sample code is writing the byte data but also opening the file on the server itself.

This won't work.

You need to stream the file data from the webservice to the client browser and then opne the file in the client machine.

Look here for a similar thread. (Wow, seems like I answered that as well:))

Download pdf using webservice
Share this answer
BillWoodruff 3-Nov-14 12:54pm    
sorry im new here, btw this is an wpf application how can this code open a file on server side?
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900