0

I have a folder in my WPF project containing pdf files as shown below.

enter image description here

How do I access the files?

I have tried this:

 fileList.Add(new FileList() { FileName = "AngularJS Example", FilePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "//media/pdf/AngularJS-Example.pdf" });

And Also this:

            fileList.Add(new FileList() { FileName = "AngularJS Up And Running", FilePath = "Reader.AngularJS-Example.pdf" });

The FilePath is a string which is suppose to be passed to a Foxit PDF Viewer method expecting string.

this.axFoxitCtl1.OpenFile(filePath);

Adjustment:

File:

fileList.Add(new FileList() { FileName = "AngularJS Up And Running", FilePath = "Reader.AngularJS-Example.pdf" });

Viewer:

public ViewerTemplate(string fileName)
        {
            InitializeComponent();
            var assembly = Assembly.GetExecutingAssembly();
            var resourceName = fileName;

            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
            using (StreamReader reader = new StreamReader(stream))
            {
                string result = reader.ReadToEnd();
                this.axAcroPDF1.LoadFile(result);

            }
        }
codegrid
  • 977
  • 2
  • 13
  • 33
  • What is a Build Action for your pdf files? And what is the value of "Copy to Output Directory" property? – chameleon Mar 02 '16 at 09:10
  • The build action should be embedded – codegrid Mar 02 '16 at 09:15
  • if it's marked as EmbededResource you should read it as stream, not as a file: http://stackoverflow.com/questions/3314140/how-to-read-embedded-resource-text-file – chameleon Mar 02 '16 at 09:19
  • I have adjusted the code but the viewer is not rendering the pdf. – codegrid Mar 04 '16 at 06:44
  • I think it shoud work another way. I'm not sure but I think LoadFile method expects a path to file in a file system. In your code you read the content of the file. You need to check the documentation of this pdf viewer to find out how to read pdf from memory. Maybe it's better to read stream to byte array and send it to pdf viewer. – chameleon Mar 04 '16 at 08:43
  • Another possible solution is to save stream to a temporary file and send the path to this file as a parameter to LoadFile. – chameleon Mar 04 '16 at 08:50
  • How do I achieve this? – codegrid Mar 06 '16 at 17:12

0 Answers0