0

I'm trying to get an application to find its current path/directory, and then use that to install a zip file then extract it into the specified location. (SelFolder)

Dim progDirectory As String

Public Sub Install()
    progDirectory = Environment.GetFolderPath(System.Environment.CurrentDirectory)
    My.Computer.FileSystem.WriteAllBytes(SelFolder & "\Resource.zip", progDirectory, False)
    Unzip(SelFolder & "\Resource.zip", SelFolder)
End Sub

The error is where progDirectory is when using the WriteAllBytes Command.

Any help would be greatly appreciated! :)

3
  • The second argument of WriteAllBytes should be the bytes you're trying to write. You're currently passing in a string... what is the point of WriteAllBytes? i.e what are you trying to achieve with it? Commented Jul 14, 2013 at 13:01
  • The zip file is written to a directory that is chosen by the user, then unzipped, and deleted. Works if I use My.Resources.Resource code. But i want it separate of the program. Commented Jul 14, 2013 at 13:42
  • Why not just use System.IO.File.Copy method to copy the zip file to the user selected directory? Commented Jul 14, 2013 at 15:15

1 Answer 1

1

It seems that you are misunderstanding how to use WriteAllBytes.

The second parameter of FileSystem.WriteAllBytes is the data to write (byte[] data). You're passing a string that indicates a path to a file instead, that's why you get this error.

Sign up to request clarification or add additional context in comments.

8 Comments

So how would I change this to fix the issue? Or rather, how might I convert the string into a byte array?
Are you trying to write progDirectory to your file? Take into account that this is not the way to create a zip file, but if the only thing you want is converting progDirectory to byte array, that could be easily done.
I will distribute the .exe and the .zip file, so I want to obtain the location of the .exe file. (or the .zip if possible) If I use: My.Computer.FileSystem.WriteAllBytes(SelFolder & "\Resource.zip", My.Resources.Resource, False) it works fine.
@user2580915: What I'm trying to say is that you don't write plain bytes to a zip file. You're supposed to compress the information. You have many options to create zip files out there.
I'm not creating a .zip file. I'm trying to find the location of it and then unzip and install from their. It works fine if the location is My.Resources.Resource
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.