.net - How do I reference a local resource in generated HTML in WinForms WebBrowser control? -
i'm using winforms webbrowser control display content in windows forms app. i'm using documenttext property write generated html. part working spectacularly. want use images in markup. (i prefer use linked css , javascript, however, can worked around embedding it.)
i have been googling on course of several days , can't seem find answer title question.
i tried using relative reference: app exe in bin\debug. images live in "images" directory @ root of project. i've set images copied output directory on compile, end in bin\debug\images*. use reference "images..." thinking relative exe. however, when @ image properties in embedded browser window, see image url "about:blankimages/*". seems relative "about:blank" when html written control. lacking location context, can't figure out use relative file resource reference.
i poked around properties of control see if there way set fix this. created blank html page, , pointed browser @ using "navigate()" method, using full local path file. worked fine browser reporting local "file:///..." path blank page. again wrote browser, time using document.write(). again, browser reports "about:blank" url.
short of writing dynamic html results real file, there no other way reference file resource?
i going try 1 last thing: constructing absolute file paths images , writing html. html being generated using xsl transform of serialized object's xml i'll need play xsl parameters take little time i'm not familiar them.
here's do, although should mention use custom web browser remove such things ability right-click , see old ie context menu:
public class htmlformatter { /// <summary> /// indicator uri referencing local /// file path. /// </summary> public static readonly string file_url_prefix = "file://"; /// <summary> /// path separator html paths. /// </summary> public const string path_separator = "/"; } // need add proper paths each image source // designation match being placed on disk. string html = htmlformatter.replaceimagepath( myhtml, htmlformatter.file_url_prefix + applicationpath.fullapppath + htmlformatter.path_separator);
basically, need have image path has file uri, e.g.
<img src="file://applicationpath/images/myimage.gif">
Comments
Post a Comment