获取FixedDocuments出一个固定文档序列的序列、文档、FixedDocuments

2023-09-06 08:29:17 作者:去和幸福接吻

很简单:

我有我拉过盘的XPSDocument。我想获得FixedDocuments出这个XpsDocument的,但我已经打了一下栽了跟头,因为我只能得到一个固定文档序列,我可以不知道如何从这个序列拉XpsDocuments。

I have an XPSDocument that I am pulling off of disk. I would like to get the FixedDocuments out of this XpsDocument, but I've hit a bit of a cropper since I can only get a FixedDocumentSequence, and I can't work out how to pull the XpsDocuments from this sequence.

到目前为止,我已经试过类似:

So far I've tried something like:

FixedDocument doc = (FixedDocument)myFixedDocSequence.References.First();   

这是投不工作,但它说明了什么我想要实现的。

That cast doesn't work, but it illustrates what I'm trying to achieve.

推荐答案

myFixedDocSequence.References.First(); 应该返回一个 DocumentReference的。从这个代替铸造你试图使用DocumentReference.GetDocument法,它返回一个固定文档?在code是这样的:

myFixedDocSequence.References.First(); should return a DocumentReference. From that instead of casting have you tried using the DocumentReference.GetDocument method, which returns a FixedDocument? The code would look like this:

DocumentReference docReference = myFixedDocSequence.References.First();
FixedDocument doc = docReference.GetDocument(false);

阅读链接到上面的 GetDocument 参数选项的详细信息的文档。此外,除非你确定 References.First()将不能为空,可以考虑使用 FirstOrDefault()和检查对于空之前使用返回的对象。

Read the documentation linked to above for more information on the GetDocument parameter options. Also unless you're sure References.First() won't be null, consider using FirstOrDefault() and checking for null before using the returned object.