Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在WPF项目资源中查找文件_C#_Wpf_Pdfviewer - Fatal编程技术网

C# 在WPF项目资源中查找文件

C# 在WPF项目资源中查找文件,c#,wpf,pdfviewer,C#,Wpf,Pdfviewer,我的WPF项目中有一个包含pdf文件的文件夹,如下所示 如何访问这些文件 我试过这个: fileList.Add(new FileList() { FileName = "AngularJS Example", FilePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "//media/pdf/AngularJS-Example.pdf" }); 还有: fileLis

我的WPF项目中有一个包含pdf文件的文件夹,如下所示

如何访问这些文件

我试过这个:

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

            fileList.Add(new FileList() { FileName = "AngularJS Up And Running", FilePath = "Reader.AngularJS-Example.pdf" });
FilePath是一个字符串,假定它被传递给一个需要字符串的Foxit PDF Viewer方法

this.axFoxitCtl1.OpenFile(filePath);
调整:

文件:

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

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

            }
        }

什么是pdf文件的生成操作?“复制到输出目录”属性的值是什么?如果构建操作标记为EmbeddedResource,则应将其嵌入。您应该将其读取为流,而不是文件:我已经调整了代码,但查看器没有呈现pdf。我认为它应该以另一种方式工作。我不确定,但我认为LoadFile方法需要文件系统中的文件路径。在代码中读取文件的内容。您需要查看此pdf查看器的文档,了解如何从内存中读取pdf。也许最好将流读取到字节数组并将其发送到pdf查看器。