(help) Extract resources to folder (Visual Basic 2008)

Extract stuff from the Resource folder, and put it into a folder.

Page 1 of 1

3 Replies - 12605 Views - Last Post: 26 May 2012 - 06:58 AM Rate Topic: -----

#1 n00bl3z  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-December 09

(help) Extract resources to folder (Visual Basic 2008)

Post icon  Posted 01 December 2009 - 06:25 PM

Alrighty!
I've been trying codes like:
My.Computer.FileSystem.CopyFile(My.Resources.File, "C:\b.jpeg")


I've tried declaring the file
Dim Targetfile as String
Targetfile = My.Resources.File


and i get an error because Resources' can't be converted to string...

I'd like some help, i've been working on this for a while lol.

This post has been edited by n00bl3z: 01 December 2009 - 06:35 PM


Is This A Good Question/Topic? 0
  • +

Replies To: (help) Extract resources to folder (Visual Basic 2008)

#2 kasbaba  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 133
  • Joined: 03-November 08

Re: (help) Extract resources to folder (Visual Basic 2008)

Posted 02 December 2009 - 12:43 AM

View Postn00bl3z, on 1 Dec, 2009 - 05:25 PM, said:

Alrighty!
I've been trying codes like:
My.Computer.FileSystem.CopyFile(My.Resources.File, "C:\b.jpeg")


I've tried declaring the file
Dim Targetfile as String
Targetfile = My.Resources.File


and i get an error because Resources' can't be converted to string...

I'd like some help, i've been working on this for a while lol.


First of all make sure that all resources are "Embedded Resource". You can do this by going to the Properties of the Resource, and then choosing "Embedded Resource" from the Build property item list.
Second, you need to write following code in a module.
Imports System.Reflection
Imports System.IO

Public Sub SaveToDisk(ByVal resourceName As String, ByVal fileName As String)
		' Get a reference to the running application.
		Dim assy As [Assembly] = [Assembly].GetExecutingAssembly()

		' Loop through each resource, looking for the image name (case-insensitive).
		For Each resource As String In assy.GetManifestResourceNames()
			If resource.ToLower().IndexOf(resourceName.ToLower) <> -1 Then
				' Get the embedded file from the assembly as a MemoryStream.
				Using resourceStream As System.IO.Stream = assy.GetManifestResourceStream(resource)
					If resourceStream IsNot Nothing Then
						Using reader As New BinaryReader(resourceStream)
							' Read the bytes from the input stream.
							Dim buffer() As Byte = reader.ReadBytes(CInt(resourceStream.Length))
							Using outputStream As New FileStream(fileName, FileMode.Create)
								Using writer As New BinaryWriter(outputStream)
									' Write the bytes to the output stream.
									writer.Write(buffer)
								End Using
							End Using
						End Using
					End If
				End Using
				Exit For
			End If
		Next resource
	End Sub



Now to use the subroutine "SaveToDisk", you need to write the following code:
SaveToDisk([Resource Name with Extension-use the same case as used in the filename], [Output path with FileName & extension])

Example:
SaveToDisk("tickMark.gif", "C:\MyFolder\tickmark.gif")


Hope this Helps !!
Was This Post Helpful? 2
  • +
  • -

#3 stanito33  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-May 12

Re: (help) Extract resources to folder (Visual Basic 2008)

Posted 26 May 2012 - 06:17 AM

Where to find "Embedded Resource" ? Please helpp ;)
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: (help) Extract resources to folder (Visual Basic 2008)

Posted 26 May 2012 - 06:58 AM

The post above yours tells you, closely reread it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1