Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get FixedDocuments out of a FixedDocumentSequence

Tags:

c#

.net

xps

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.

like image 371
MoominTroll Avatar asked Dec 04 '25 19:12

MoominTroll


1 Answers

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.

like image 168
Ahmad Mageed Avatar answered Dec 06 '25 09:12

Ahmad Mageed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!