Hack Forums
[.NET] Moving a file in vb - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Moving a file in vb (/showthread.php?tid=4462772)



Moving a file in vb - scaa - Sep 25, 2014

So I have a .dll file that I want to move from my reasources to the selected path from FolderBrowserDialog1 with a button click but after trying a few different things I still cant find something that works, anybody got any ideas of how this could be done ? Thanks. 🤝

Here's what i've tryed;
PHP Code

<?php 
My
.Computer.FileSystem.MoveFile(My.Resources.clr.ToString, FolderBrowserDialog1.SelectedPath) 
and
PHP Code

<?php 
Dim FileToMove 
As String
      Dim MoveLocation 
As String

      FileToMove 
= True

      FileToMove 
= "My.Resources.clr"
      
MoveLocation = FolderBrowserDialog1.SelectedPath

      
If System.IO.File.Exists(FileToMove) = True Then

      System
.IO.File.Move(FileToMove, MoveLocation)
      
MsgBox("File Moved")

      
End If 
and others i found online but can't remember.


* - Nikey646 - Sep 25, 2014

A .dll stored in the resources would be stored as Bytes[].

This means you will want to do something along the lines of:

Code
Using(var Stream = new StreamWriter(FolderBrowserDialog1.SelectedPath)
    Stream.Write(My.Resources.clr.ToArray();

The above is C#, and you'll need to convert it to VB if you want to use it. It may also throw errors due to being typed of the top of my head.


* - scaa - Sep 26, 2014

Tryed converting but it threw back some errors, not moved into C# yet either, thanks for the help though. 🤝


* - Nikey646 - Sep 26, 2014

(Sep 26, 2014 12:09 AM)scaa Wrote:  Tryed converting but it threw back some errors, not moved into C# yet either, thanks for the help though. 🤝

Look up a tutorial for Writing Byte's to a file for VB, that's the basic concept that you want to look at. Sorry the code wasn't of more help.


* - 8R4u2213 - Sep 26, 2014

do you get any error ?

you can try writeallbytes

Dim data() As Byte = System.IO.File.ReadAllBytes(fileToMove)
System.IO.File.WriteAllBytes(path, data)