Click here to Skip to main content
15,510,022 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have to download the pdf file from the folder where i have stored already in c:\ drive using Datagridview cell content click in c# windows application.

pdf file downloaded and adobe reader couldn't read that file

Adobe reader could not open file 'ForwardLoadHistory.pdf' 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 corrcetly decoded)".

What I have tried:

using (SaveFileDialog sfd = new SaveFileDialog())
                     {
                         //Set Save dialog properties
                         sfd.Filter = "Files (*" + extn + ")|*" + extn;
                         sfd.Title = "Save File as";
                         sfd.CheckPathExists = true;
                          sfd.RestoreDirectory = true;
                         sfd.FileName = matchfile;




                         if (sfd.ShowDialog() == DialogResult.OK)
                         {


                          if((mystream = sfd.OpenFile()) != null)
                              {

                                  mystream.Close();
                              }
                         }
                     }
Posted
Updated 30-Mar-22 4:12am
Comments
Richard MacCutchan 30-Mar-22 8:49am    
You forgot to write the data to the file.

1 solution

You open the file:
if((mystream = sfd.OpenFile()) != null)

You close the file:
mystream.Close();
But all that does is delete any existing file of that name, and create a new, empty file.
Adobe won't be able to read the empty file as it contains no PDF data. So rightly, it complains.
Somewhere, you have PDF data that you want in the file - at some point to need to pass it to the mystream.Write method, probably using this overload: Stream.Write Method (System.IO) | Microsoft Docs[^]

We can't be more specific, we have no idea where your data is or how it is stored!
 
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