tags:

views:

90

answers:

1

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.

+1  A: 

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.

Ahmad Mageed
Cheers. I had a bit of trouble finding documentation on anything late in the day, but that might be because my head was full of fog :)And don't worry, I do normally use FirstOrDefault() :)
MoominTroll