Viewing an XPS document with malformed URI's in WPF -
i'm trying use documentviewer (or, more specifically, documentviewer's documentpageview) load presentation saved powerpoint xps.
however, author of slides being clever , entered 1 of urls pseudo-regex (e.g. http://[blog|www]mywebsite.com
). built in xps viewer able load document without problem. however, documentviewer throws exception because tries validate uri:
failed create 'navigateuri' text 'http://[blog|www]mywebsite.com'
i of course go slide , fix uri document displays. however, since can't control documents used application, i'd prefer find way display document in spite of invalid uri's (like xps viewer).
any thoughts?
the documentviewer trying create uri instance provided url. if url isn't valid, operation fail.
you can prevent happening performing validation on urls provided author. (writing without testing, there may syntax errors)
public static bool isvalidurl(this string url) { if(string.isnullorwhitespace(url) return false; try { var uri = new url(url); return true; } catch { // if implementing idataerrorinfo rather using // lousy extension method catch exception // here , display user return false; } }
Comments
Post a Comment