How To Copy A File To The HardDrive?

Simcoder

Well-known member
Joined
Apr 18, 2003
Messages
124
Location
Texas
Ok Heres the problem, I have 2 Files
File 1) We will call it Application_ONE
File 2) We will call it TextFile_TWO

Now I want to embedd these 2 files into the executable.
I have an idea of how to do that. I believe I add an existing item
to the project and choose Embedded Resource.

Next I want to copy both of those files to a path...
example Path = C:\ProgramFiles

How do I code a button that will copy both the application and the text file to the designated path. I would really appreciate any help from anyone! Thanx
-=Simcoder=-
 
Hello this might help you while copying file

Code:
Imports System
Imports System.IO

Public Class Test
    Public Shared Sub Main()
         Specify the directories you want to manipulate.
        Dim path As String = "c:\Program Files\MyTest.txt"
        Dim path2 As String = path + "temp"

        Try
            Dim fs As FileStream = File.Create(path)
            fs.Close()

             Ensure that the target does not exist.
            File.Delete(path2)

             Copy the file.
            File.Copy(path, path2)
            Console.WriteLine("{0} copied to {1}", path, path2)

             Try to copy the same file again, which should succeed.
            File.Copy(path, path2, True)
            Console.WriteLine("The second Copy operation succeeded, which was expected.")

        Catch
            Console.WriteLine("Double copying is not allowed, which was not expected.")
        End Try
    End Sub
End Class
 
Thanks, that helps me understand how the copy process is set up! Do you think you could tell me how to reference an object that does not have a path? Say an embedded project image, application or text file, How would I copy this from the embedded .exe file to the specified path. Thanks
-=Simcoder=-
 
there are several methods for this. images and other strings are stored in EXE Resources Section.

An EXE File has severel parts , The analysis of the managed EXE file structure employs the following common definitions:

File pointer The location of an item within the file itself, before it is processed by the loader. This location is a position (an offset) within the file as it is stored on disk.

Relative virtual address (RVA) The address of an item once it has been loaded into memory, with the base address of the image file subtracted from it
 
Thanks alot Madz, Im going to have to play around with it until I get it working. Youve been a big help! :)
 
Hmm, Im still having a problem, getting the exe file to be copied :(
I used the System.Reflection, but Im still not sure, what is the actual code to copy something that is embedded to a specific path!

Can someone give me an example? For Instance, I embedded an exe file called App_One.exe How do I copy the file to my C:\ Drive.
Some sample code would be nice so I could understand it.
Thanks
-=Simcoder=-
 
Oh Dear, some where i have searched about C# Resources Editor code in which you might get some good example of how to extract resources from EXE files and so on
 
Back
Top