开发者

Get FixedDocuments out of a FixedDocumentSequence

Fairly simple:

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

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜