Resolved What's the best way to include the .dic fit in the .exe fil

aaaron

Well-known member
Joined
Jan 23, 2011
Messages
213
Programming Experience
10+
VB.NET:
        Dim dictionary0 As WordList = WordList.CreateFromFiles("C:\Users\Aaron\CAG Suite\English Dic\English (American).dic")
        Dim ok0 As Boolean = dictionary0.Check("Color")
        Dim suggestions As IEnumerable(Of String) = dictionary0.Suggest("Color")
        Dim notOk0 As Boolean = dictionary0.Check("Colour")

'Or

 Using dictionaryStream2 As Stream = File.OpenRead("C:\Users\Cal\CG Visual Studio\Net6\CAG Suite\English Dic\English (American).dic")
            Using affixStream2 As Stream = File.OpenRead("C:\Users\Cal\CG Visual Studio\Net6\CAG Suite\English Dic\English (American).aff")
                Dim dictionary2 As WordList = WordList.CreateFromStreams(dictionaryStream2, affixStream2)
                Dim ok2 As Boolean = dictionary2.Check("the")
                Dim notOk2 As Boolean = Dictionary2.Check("teh")
            End Using
        End Using

I'm guessing that WordList.CreateFromFiles will also need to read the .aff file so the second approach might be better.

The above works OK but the dictionary files should be embedded in the .exe file.

I know I did something like this in the past but can't rmember how.

What's the best way to include the .dic fit in the .exe file.
 
Last edited:
Solution
If you want to embed the data files in the executable then you can do so as resources. Open the Resources page of the project properties and add the files there. The file extension is dropped from the resource name so you'll need to change the original file names or the resource names to differentiate them clearly.

You can then access the file contents via the corresponding property of My.Resources. The data type of that property depends on the original file. I'm not sure what it will be in your case but I suspect that it will be a String or maybe a Byte array or, less likely still, a Stream of some kind. In the last case, you can call WordList.CreateFromStreams and you're done. In the first two cases, if...
If you want to embed the data files in the executable then you can do so as resources. Open the Resources page of the project properties and add the files there. The file extension is dropped from the resource name so you'll need to change the original file names or the resource names to differentiate them clearly.

You can then access the file contents via the corresponding property of My.Resources. The data type of that property depends on the original file. I'm not sure what it will be in your case but I suspect that it will be a String or maybe a Byte array or, less likely still, a Stream of some kind. In the last case, you can call WordList.CreateFromStreams and you're done. In the first two cases, if that WordList class has a method that will accept either a data String, as opposed to a file path String, or a Byte array then you can call that method and pass the data directly.

Otherwise, you have two options. One would be to save the data to temporary files and then call WordList.CreateFromFiles. The other would be to write the data to a MemoryStream objects and pass them to WordList.CreateFromStreams.

I suggest that you create the resources first and name them appropriately, then see what data types those properties are. You can then decide how to proceed from there.
 
Solution
Back
Top