I've been developing an "IDE" for custom software that relies on a web browser control to display it's information. The software uses an external file "common.vbs" to access common functions within it's web pages. Sprinkled throughout various web pages within the application is the html tag:
<script LANGUAGE="VBScript" src="common.vbs"></script>
Dim sPath As String = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)
sPath = Path.Combine(sPath, "common.vbs")
Dim fs As FileStream = File.Create(sPath)
Dim sData As String = My.Resources.common
Dim Info As Byte() = New UTF8Encoding(True).GetBytes(My.Resources.common)
fs.Write(Info, 0, Info.Length)
Catch ex As Exception
An error has occurred in the script on this page
Error: Script error
window.external.DoHelp "", "", -1, -1
Function SQLDate( d)
SQLDate = "'" & DatePart("yyyy", d) & "-" & DatePart("m", d) & "-" & DatePart("d", d) & "'"
Function MonitorJob( jobId)
on error resume next
window.external.UIControl.MonitorJob jobId, 0
Part of the problem is how the web control is loaded. Using the document methods circumvents accessing the file system because no base location is used. In order to access items in the file system, the "source page" needs to be in the file system. The next part of the problem was getting the resources into the file system. Below is the code that I used. Important note: for demonstration reasons only, the code for the Temp Path is located inside this routine. It actually resides out side the routine for access in other routines.
Sub UpdateFiles(sData) 'Write all the dependent files into the working folder. Dim sLocalPath As String = Path.Combine(Path.GetTempPath, Guid.NewGuid.ToString) Do While Directory.Exists(TempWorkingPath) Or File.Exists(TempWorkingPath) sLocalPath = Path.Combine(Path.GetTempPath, Guid.NewGuid.ToString) Loop Directory.CreateDirectory(sLocalPath) File.WriteAllBytes(Path.Combine(sLocalPath, "common.vbs"), System.Text.Encoding.UTF32.GetBytes(My.Resources.common)) Dim aImageList() As String = Split(My.Resources.M3ImageList, vbCrLf) Dim sImageList As String = Replace(Join(Split(My.Resources.M3ImageList, vbCrLf), ","), "-", "_") Dim ResourceSet As Resources.ResourceSet = My.Resources.ResourceManager.GetResourceSet(Globalization.CultureInfo.CurrentCulture, True, True) For Each Dict As DictionaryEntry In ResourceSet.OfType(Of Object)() If TypeOf (Dict.Value) Is Drawing.Image Then If InStr(sImageList, Dict.Key, vbTextCompare) > 0 Then Dim ImageConverter As New ImageConverter Dim aBytes() As Byte = ImageConverter.ConvertTo(Dict.Value, GetType(Byte())) Dim sName As String = Replace(Dict.Key.ToString & ".gif", "_", "-") File.WriteAllBytes(Path.Combine(sLocalPath, sName), aBytes) End If End If Next File.WriteAllText(Path.Combine(sLocalPath, "index.html"), sData) End Sub
I used a separate resource file that listed all of the files I needed to drive this routine. One point of note, when I imported all of the GIF's, the -'s were converted into _'s, thus the replace statements. I also used a filter (the Instr command) so that only the items in the list were exported.
I spent a lot of time on this, and I hope others will find it useful!