views:

24

answers:

0

Dear all, I have a WinForm application which display some local html file with the WebBrowser, the html file also have some linked stylesheet file and javascript file and these files should be deployed with the application and html files. But sometimes we miss some javascript or stylesheet file in the deployment package, now I want to log which file missed while the html file loading in the WebBrowser. I have an implement as following, but I'm not sure whether there are better ideas, any suggestion?

My current implement:

        var document = webBrowser1.Document.DomDocument as DispHTMLDocument;

        foreach (IHTMLStyleSheet styleSheet in document.styleSheets)
        {
            Uri linkUri = new Uri(this.webBrowser1.Url, styleSheet.href);
            if (!File.Exists(linkUri.LocalPath))
            {
                MessageBox.Show(linkUri.LocalPath);
            }
        }

        foreach (IHTMLScriptElement script in document.scripts)
        {
            Uri linkUri = new Uri(this.webBrowser1.Url, script.src);
            if (!File.Exists(linkUri.LocalPath))
            {
                MessageBox.Show(linkUri.LocalPath);
            }
        }