Read a Text File Embedded as a Resource in a dll with vb.net

Good Morning! I hope your thanksgiving was a happy one. My family is in Minnesota due to the holiday where her brother is getting married so I am here by myself. I ate a stir fry for dinner last night. But really its okay.

Today’s topic is related to my next post concerning how you can save tags to always be included in the Automatic Tag Generation Plugin I am creating for Windows Live Writer. Basically, we want to read a text file that will store those words, which is embedded as a resource file in the dll for the plugin. Happy shopping and make it a great day!

Sub GetFileContents(ByVal FileName As String, ByVal DataTable As DataTable)
        Dim this As [Assembly]
        this = System.Reflection.Assembly.GetExecutingAssembly
        For Each resource As String In this.GetManifestResourceNames()
            If resource.IndexOf(FileName) > -1 Then
                Dim inFile = New System.IO.StreamReader(this.GetManifestResourceStream(resource))
                While inFile.Peek() > -1
                    Dim readline As String = inFile.ReadLine
                    Dim row As DataRow = DataTable.NewRow
                    row.Item(FileName) = readline
                    DataTable.Rows.Add(row)
                End While
            End If
        Next

 

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: