.net 读取资源文件内容示例代码
Sub Main()
Dim res As New ResourceReader(“CustomControls.Properties.Resources.resources”)
‘该文件放到bin
Dim dics As IDictionaryEnumerator = res.GetEnumerator()
While dics.MoveNext()
Dim filepath As String = dics.Key.ToString()
filepath = Path.Combine(“d:\aa\”, filepath)
‘保存到指定目录
filepath = Path.GetFullPath(filepath)
Dim p = Path.GetDirectoryName(filepath)
‘要创建的目录
If Not Directory.Exists(p) Then
Directory.CreateDirectory(p)
End If
If TypeOf dics.Value Is System.Drawing.Bitmap Then
Dim ms As New IO.MemoryStream
CType(dics.Value, System.Drawing.Bitmap).Save(ms, CType(dics.Value, System.Drawing.Bitmap).RawFormat)
My.Computer.FileSystem.WriteAllBytes(filepath & “.png”, ms.ToArray, False)
Continue While
End If
If TypeOf dics.Value Is String Then
Dim s As String = DirectCast(dics.Value, String)
My.Computer.FileSystem.WriteAllText(filepath & “.xml”, s, False)
End If
If TypeOf dics.Value Is Byte() Then
Dim s As Byte() = DirectCast(dics.Value, Byte())
Dim fileSize As Integer = CInt(s.Length)
‘Dim fileContent As Byte() = New Byte(fileSize – 1) {}
‘s.Read(fileContent, 0, fileSize)
Dim fs As FileStream
Dim fi As FileInfo = New System.IO.FileInfo(filepath)
fs = fi.OpenWrite()
fs.Write(s, 0, fileSize)
fs.Close()
End If
End While
res.Close()
End Sub