how do you copy/move a file (image,accdb,...) out of resources?

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4

57 Replies - 6405 Views - Last Post: 17 May 2012 - 11:40 AM Rate Topic: -----

#16 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 211
  • Joined: 10-March 12

Re: how do you copy/move a file (image,accdb,...) out of resources?

Posted 12 May 2012 - 12:09 PM

i have highlighted you where to click, in the picture. after you click there, you can set the built action.

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#17 digitaldevelopment  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 168
  • Joined: 30-April 12

Re: how do you copy/move a file (image,accdb,...) out of resources?

Posted 12 May 2012 - 12:18 PM

forget about everything I said, it works completely :D thank you SOO MUCH!!!!!
Was This Post Helpful? 0
  • +
  • -

#18 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 211
  • Joined: 10-March 12

Re: how do you copy/move a file (image,accdb,...) out of resources?

Posted 12 May 2012 - 12:19 PM

i am happy i could help you :)
Was This Post Helpful? 0
  • +
  • -

#19 digitaldevelopment  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 168
  • Joined: 30-April 12

Re: how do you copy/move a file (image,accdb,...) out of resources?

Posted 12 May 2012 - 12:24 PM

yes you really were helpfull! now I am gonna do the part to write update the code and import it back.
would you like me to post the resulting code?

This post has been edited by digitaldevelopment: 12 May 2012 - 12:26 PM

Was This Post Helpful? 0
  • +
  • -

#20 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 211
  • Joined: 10-March 12

Re: how do you copy/move a file (image,accdb,...) out of resources?

Posted 12 May 2012 - 12:32 PM

yes, and if i can help you in any other way, just let me know
Was This Post Helpful? 0
  • +
  • -

#21 digitaldevelopment  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 168
  • Joined: 30-April 12

Re: how do you copy/move a file (image,accdb,...) out of resources?

Posted 13 May 2012 - 06:00 AM

well for the moment I am using this code:
Imports System.Reflection
Imports System.IO 'this is for the writing of the .HTML files
Imports System
Public Class webGenerator

    Private Sub webgenerating_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles webGenerating.DoWork
        Dim naam As String = NaamTextBox.Text.ToString
        Dim achternaam As String = AchternaamTextBox.Text.ToString
        Dim leeftijd As String = LeeftijdTextBox.Text.ToString
        Dim ID As String = IDTextBox.Text.ToString
        Dim destkop As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
        Directory.CreateDirectory(destkop + "\websites\")
        Dim writer As StreamWriter = New StreamWriter(destkop + "\websites\" + naam + "_Profilepage.html")
        writer.WriteLine("<html>")
        writer.WriteLine("<head><title>Hello world!</title><style>html{background-color:#b0c4de;}#profile{ position: relative; top: 50%; left: 50%; border: 2px; }</style></head>")
        writer.WriteLine("<body>")
        writer.WriteLine("<div id='profile'>")
        writer.WriteLine("<p>your name is: " + naam + " " + achternaam + "</p>")
        writer.WriteLine("<p>your age is: " + leeftijd + "</p>")
        writer.WriteLine("<p>with ID " + ID + "</p>")
        writer.WriteLine("</div>")
        writer.WriteLine("</body>")
        writer.WriteLine("</html>")
        writer.Close()
        Me.PersoneelBindingSource.MoveNext()
        generateGeneralHTML("index.html")
        generateGeneralHTML("style.css")
        generateGeneralHTML("BG.jpg")
    End Sub

    Private Sub PersoneelBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles PersoneelBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.PersoneelBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.BedrijfDataSet)

    End Sub

    Private Sub webGenerator_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'BedrijfDataSet.personeel' table. You can move, or remove it, as needed.
        Me.PersoneelTableAdapter.Fill(Me.BedrijfDataSet.personeel)

    End Sub

    Private Sub generateAll_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles generateAll.DoWork
        Dim amount As Integer = Me.PersoneelBindingSource.Count
        Dim current As Integer = 0
        Me.PersoneelBindingSource.MoveFirst()
        While current < amount
            If webgenerating.IsBusy = False Then
                webgenerating.RunWorkerAsync()
                current = current + 1
            End If
        End While
    End Sub

    Private Sub btnGenerateAll_Click(sender As Object, e As EventArgs) Handles btnGenerateAll.Click
        MsgBox("generating all webpages, starting when you close this pop-up box", MsgBoxStyle.Information)
        generateAll.RunWorkerAsync()
        MsgBox("Done!", MsgBoxStyle.Information)
    End Sub

    Private Sub btnGenerateThis_Click(sender As Object, e As EventArgs) Handles btnGenerateThis.Click
        MsgBox("generating a webpage for this profile only: " + Me.NaamTextBox.Text.ToString, MsgBoxStyle.Information)
        webGenerating.RunWorkerAsync()
        MsgBox("Done!", MsgBoxStyle.Information)
    End Sub
    Public Function generateGeneralHTML(file As String)
        Try
            Dim filepath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
            filepath = filepath + "\websites\" + file
            Dim MyStream As System.IO.Stream
            MyStream = System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream("eindwerk." + file)
            Dim MyFileStream As New System.IO.FileStream(filepath, FileMode.Create)
            Dim MyBinaryWriter As New BinaryWriter(MyFileStream)
            Try
                Dim MyByte As Byte = MyStream.ReadByte
                While Not MyByte = -1
                    MyBinaryWriter.Write(MyByte)
                    MyByte = MyStream.ReadByte
                End While
            Catch ex As System.NullReferenceException
                MsgBox("an error occured in the writing, written files are corrupted", MsgBoxStyle.Critical)
            Catch ex As Exception
            Finally
                MyFileStream.Close()
            End Try
        Catch null As NullReferenceException
            Console.WriteLine("nullereference in function generateGeneralHTML()")
        End Try
    End Function
End Class


and it does what it is supposed to do, it copies the database (which uses similiar code) perfectly but this writes the file to the folder it is supposed to write it to... only the files are each 0kb big. with other words; they are all empty. the images, websites...all empty
do you by chance know how this is possible?
Was This Post Helpful? 0
  • +
  • -

#22 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 211
  • Joined: 10-March 12

Re: how do you copy/move a file (image,accdb,...) out of resources?

Posted 13 May 2012 - 06:51 AM

i remember that when i also used this code, i encountered the same problem, but i cant remember for the moment what was the solution for it. Let me research about the subject again. But i want to ask you something: you used my code as a function to which you pass the file as an argument, and you say it does copy the files, but they are empty. What i want to ask is: did you tryed to use the code not as a function? i mean, not passing an argument to it, but instead writing the file specificaly to it? Like, instead of this: MyStream = System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream("eindwerk." + file) using this: MyStream = System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream("eindwerk.bedrijf.accdb") etc etc. Would it still create 0 kb files? Try it and let me know the results. Also, if you want to see an example of how i implemented this code, check this project, you can find the relevant code in the BeginInstalation.vb form, region "copy files". Have a look at it and try to adapt it to your needs.

Also, just a personal remark: if a function does not return anything, than its not a function. You may want to change Public Function generateGeneralHTML(file As String) to Public Sub generateGeneralHTML(file As String)...
Was This Post Helpful? 0
  • +
  • -

#23 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 211
  • Joined: 10-March 12

Re: how do you copy/move a file (image,accdb,...) out of resources?

Posted 16 May 2012 - 06:13 AM

well, did you manage to solve your problem?

This post has been edited by rusoaica: 16 May 2012 - 06:13 AM

Was This Post Helpful? 0
  • +
  • -

#24 digitaldevelopment  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 168
  • Joined: 30-April 12

Re: how do you copy/move a file (image,accdb,...) out of resources?

Posted 16 May 2012 - 06:28 AM

no I had it working for some time, so far I know. but a while back all of a sudden it only produced empty files. here is what I have now:
Private Sub btnLogIn_Click(sender As Object, e As EventArgs) Handles btnOptions.Click
        Dim filepath As String = Application.StartupPath & "\bedrijf.accdb"
        MsgBox(filepath)
        Dim MyStream As System.IO.Stream = System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream("eindwerk.bedrijf.accdb")
        Dim MyFileStream As New System.IO.FileStream(filepath, FileMode.Create)
        Dim MyBinaryWriter As New BinaryWriter(MyFileStream)
        Dim readByte As New BinaryReader(MyFileStream)
        Try
            Dim MyByte As Byte = MyStream.ReadByte
            While Not MyByte = -1
                MyBinaryWriter.Write(MyByte)
                MyByte = MyStream.ReadByte
            End While
        Finally
            MsgBox("import succesfull")
            MyFileStream.Close()
        End Try
    End Sub


but even in a sub it does not fill the files
Was This Post Helpful? 0
  • +
  • -

#25 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 211
  • Joined: 10-March 12

Re: how do you copy/move a file (image,accdb,...) out of resources?

Posted 16 May 2012 - 06:34 AM

did you tryed the project i gave you the link? it is functioning there, and it writes the files as they originally were, the same sizes... try to adapt it to your code

and what did you do when it worked? what you modified to make it change the way it worked?
Was This Post Helpful? 0
  • +
  • -

#26 digitaldevelopment  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 168
  • Joined: 30-April 12

Re: how do you copy/move a file (image,accdb,...) out of resources?

Posted 16 May 2012 - 06:42 AM

I tried, but the project must be adapted to VS11, and well I am still working on the transformations. I'll let you know more soon. I had to pause this for a few days, due HUGE amounts of work, but now I have some days off and I'll be on it. by tonight it should be done
Was This Post Helpful? 0
  • +
  • -

#27 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 211
  • Joined: 10-March 12

Re: how do you copy/move a file (image,accdb,...) out of resources?

Posted 16 May 2012 - 06:43 AM

im waiting for your reply.
Was This Post Helpful? 0
  • +
  • -

#28 digitaldevelopment  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 168
  • Joined: 30-April 12

Re: how do you copy/move a file (image,accdb,...) out of resources?

Posted 16 May 2012 - 07:03 AM

ok, I'll do my best not to get distracted. in the time you are waiting, would you like to take a look at the project I had to make? you can find it here:
project
Was This Post Helpful? 0
  • +
  • -

#29 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 211
  • Joined: 10-March 12

Re: how do you copy/move a file (image,accdb,...) out of resources?

Posted 16 May 2012 - 07:12 AM

it is just an executable file, not project or sln file... and, if i were you, i would bind the background picture to the program's edges, so where the user resizes window, the background picture won't get tilled. Or, change the form's resizable to false :) nice job, anyway
Was This Post Helpful? 0
  • +
  • -

#30 digitaldevelopment  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 168
  • Joined: 30-April 12

Re: how do you copy/move a file (image,accdb,...) out of resources?

Posted 16 May 2012 - 07:17 AM

there we go, I managed to fix it. the working code looks like this:
Private Sub btnImport_Click(sender As Object, e As EventArgs) Handles btnImport.Click
        Dim path As String = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory)
        Dim filepath1 As String = Path & "bedrijf.accdb"
        Dim MyStream1 As System.IO.Stream = System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream("eindwerk.bedrijf.accdb")
        Dim MyFileStream1 As New System.IO.FileStream(filepath1, FileMode.Create)
        Dim MyBinaryWriter1 As New BinaryWriter(MyFileStream1)
        Try
            Dim MyByte As Byte = MyStream1.ReadByte
            While Not MyByte = -1
                MyBinaryWriter1.Write(MyByte)
                MyByte = MyStream1.ReadByte
            End While
        Catch ex As OverflowException
        Finally
            MyFileStream1.Close()
        End Try
        MsgBox("succes")
        My.Computer.FileSystem.RenameFile(path & "bedrijf.accdb", "bedrijf")
    End Sub


altough this of course gives an error if the file already exists, but the file works and that is the most important thing I'd say. thanks a lot! btw, could you post a link to the exe of that project you sended me? I am intrested but since VS11 messes up with older project files I'd need an exe to run it, which I'd very much like to do

and about the exe I sended, yes it is an exe since I am not sure wether older versions can read everything it those files since VS11 appearantly uses other things and stuff. also that was just a simple dummy to test wether I'd be able to make a chat application. i am planning on improving the GUI and removing that random button in the middle of the screen (I placed it there for some debugging reasons) and so on. also I shall put the formBorderStyle to fixedsingle so the user won't be able to resize (which he doesn't have to). this is actually number 1 I made. number 2 uses P2P while this one does it with TCP/IP
but if you are intrested in the source files anyway, I'll add a buton to download those to

This post has been edited by digitaldevelopment: 16 May 2012 - 07:29 AM

Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4