copy file (vb.net)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • taufik
    New Member
    • Aug 2007
    • 15

    copy file (vb.net)

    hi guys... i new person using vb.net
    i have some problem in copy a file into specific directory create by user...
    below is coding that write that may help u all to solve my problem
    [code=vbnet]
    Imports System.IO

    Public Class Form1
    Inherits System.Windows. Forms.Form

    #Region " Windows Form Designer generated code "
    #End Region

    Dim filePath As String
    Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button3.Click
    End
    End Sub

    Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2.Click
    TextBox1.Text = ""
    ComboBox1.Text = ""
    TextBox2.Text = ""
    TextBox1.Focus( )
    End Sub

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
    Dim souFile As String = TextBox2.Text
    Dim desFile = TextBox1.Text
    Dim result As StreamWriter
    'dirCopy = TextBox2.Text
    Try
    If TextBox1.Text = "" And ComboBox1.Text = "" And TextBox1.Text = "" Then
    MsgBox("sorry", MsgBoxStyle.OKO nly, "Alert")
    Else
    Directory.Creat eDirectory("C:\ Documents and Settings\Crazy_ Frog\My Documents\Visua l Studio Projects\Create Path\Document" & "\" & ComboBox1.Text & "\" & TextBox1.Text)
    File.Copy(TextB ox1.Text, TextBox2.Text)
    MsgBox("File copy successful", MsgBoxStyle.Inf ormation, "Informatio n")
    End If

    Catch ex As Exception
    MsgBox("File copy successful", MsgBoxStyle.Inf ormation, "Informatio n")
    End Try
    End Sub

    Private Sub Button4_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button4.Click
    OpenFileDialog1 .ShowDialog()
    filePath = OpenFileDialog1 .FileName
    TextBox2.Text = filePath
    End Sub
    End Class
    [/code]
    please help me... urgent...
    Last edited by Frinavale; Aug 23 '07, 07:47 PM. Reason: Added [code] tags to make more legible
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    What exactly is the problem?
    It looks ok enough.
    Although where you catch your exception you still have it display the success message, which could be confusing.

    If you have an error, try debugging it to see what the situation is when it errors.

    Comment

    • taufik
      New Member
      • Aug 2007
      • 15

      #3
      ok.... actually textbox1.text and combobox1.text represent folder that i create...
      and textbox2.text is the openFileDialog1 .showDialog() function... from the openFileDialog1 .showDialog() function i want to save the file that selected in textbox2.text to the following input user based on textbox1.text and combobox1.text...

      actually... i can create the folder based on input from user... but i cannot copy the file into the directory that user create....

      i hope u get an idea for this problem....
      thanks....

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Right I gathered that it wasn't working.
        WHAT PART is not working, surely there is an error message somewhere?

        Comment

        • taufik
          New Member
          • Aug 2007
          • 15

          #5
          Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles Button4.Click
          OpenFileDialog1 .ShowDialog()
          filePath = OpenFileDialog1 .FileName
          TextBox2.Text = filePath
          End Sub

          * this button for open file dialog where the path are written on the TextBox2.Text

          Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
          Dim result As StreamWriter
          Try
          If TextBox1.Text = "" And ComboBox1.Text = "" And TextBox1.Text = "" Then
          MsgBox("sorry", MsgBoxStyle.OKO nly, "Alert")
          Else
          Directory.Creat eDirectory("C:\Documen ts and Settings\Crazy_ Frog\My Documents\Visua l Studio Projects\Create Path\Document" & "\" & ComboBox1.Text & "\" & TextBox1.Text)
          'File.Copy(Text Box1.Text, TextBox2.Text)
          MsgBox("File copy successful", MsgBoxStyle.Inf ormation, "Informatio n")
          End If

          Catch ex As Exception
          MsgBox(ex.Messa ge)
          End Try
          End Sub

          * this Button1_Click for creating folder where the path are specifically created based on Directory.Creat eDirectory

          my problem actually are to copy the file based on TextBox2.Text (path) to the Directory.Creat eDirectory
          if i click the Button1_Click, the folder will be created but the the file based on TextBox2.Text not exist..

          and another thing... i forgotten to create an error massage....
          maybe you have an idea...

          :)

          Comment

          Working...