473,385 Members | 1,640 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

copy file (vb.net)

15
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
Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2.  
  3. Public Class Form1
  4.     Inherits System.Windows.Forms.Form
  5.  
  6. #Region " Windows Form Designer generated code "
  7. #End Region
  8.  
  9.     Dim filePath As String
  10.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  11.         End
  12.     End Sub
  13.  
  14.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  15.         TextBox1.Text = ""
  16.         ComboBox1.Text = ""
  17.         TextBox2.Text = ""
  18.         TextBox1.Focus()
  19.     End Sub
  20.  
  21.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  22.         Dim souFile As String = TextBox2.Text
  23.         Dim desFile = TextBox1.Text
  24.         Dim result As StreamWriter
  25.         'dirCopy = TextBox2.Text
  26.         Try
  27.             If TextBox1.Text = "" And ComboBox1.Text = "" And TextBox1.Text = "" Then
  28.                 MsgBox("sorry", MsgBoxStyle.OKOnly, "Alert")
  29.             Else
  30.                 Directory.CreateDirectory("C:\Documents and Settings\Crazy_Frog\My Documents\Visual Studio Projects\CreatePath\Document" & "\" & ComboBox1.Text & "\" & TextBox1.Text)
  31.                 File.Copy(TextBox1.Text, TextBox2.Text)
  32.                 MsgBox("File copy successful", MsgBoxStyle.Information, "Information")
  33.             End If
  34.  
  35.         Catch ex As Exception
  36.             MsgBox("File copy successful", MsgBoxStyle.Information, "Information")
  37.         End Try
  38.     End Sub
  39.  
  40.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  41.         OpenFileDialog1.ShowDialog()
  42.         filePath = OpenFileDialog1.FileName
  43.         TextBox2.Text = filePath
  44.     End Sub
  45. End Class
  46.  
please help me... urgent...
Aug 22 '07 #1
4 5412
Plater
7,872 Expert 4TB
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.
Aug 22 '07 #2
taufik
15
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....
Aug 23 '07 #3
Plater
7,872 Expert 4TB
Right I gathered that it wasn't working.
WHAT PART is not working, surely there is an error message somewhere?
Aug 23 '07 #4
taufik
15
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 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.EventArgs) Handles Button1.Click
Dim result As StreamWriter
Try
If TextBox1.Text = "" And ComboBox1.Text = "" And TextBox1.Text = "" Then
MsgBox("sorry", MsgBoxStyle.OKOnly, "Alert")
Else
Directory.CreateDirectory("C:\Documents and Settings\Crazy_Frog\My Documents\Visual Studio Projects\CreatePath\Document" & "\" & ComboBox1.Text & "\" & TextBox1.Text)
'File.Copy(TextBox1.Text, TextBox2.Text)
MsgBox("File copy successful", MsgBoxStyle.Information, "Information")
End If

Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

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

my problem actually are to copy the file based on TextBox2.Text (path) to the Directory.CreateDirectory
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...

:)
Aug 23 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Goran Djuranovic | last post by:
I am trying to COPY, not deploy, ASP.NET application. I know that asp.net application can be copied without any problems by using "Copy Project" menu item, but only if it doesn't have any Crystal...
0
by: Grey | last post by:
I have a ASP.NET web application which is required to copy file from windows server to Novell Netware server. I have used impersonation to connect to Netware server. The application works fine when...
9
by: MAF | last post by:
Does anyone know why in 2005 I might be getting this error everytime I try and recompile? Error 226 Unable to copy file "obj\Debug\myfile.dll" to "bin\Debug\myfile.dll". The process cannot...
5
by: Standist | last post by:
I want install software on PC in my local network. First I want copy file to the PC through default share like c$ or d$ on the PC. Then install the software through wmi. I have the administrator...
0
by: Pivalig | last post by:
Hello, i try to copy file from Pocket PC to network printer using this code : destination = "\\\\pc1\\ep1000\\Bill.txt"; File.Copy("\\Program Files\\MobileKhelner\\Bill.txt", destination); ...
2
by: CGatto | last post by:
Hi, We have just started getting the following error during compiles of our forms-based application. We are developing in VS2008, VB.Net, with Team Foundation Server-based source control. ...
9
rizwan6feb
by: rizwan6feb | last post by:
Hello everybody. I need help on how to use copy function to copy file from one computer to another ( or any other way i can copy the file). The computers are on a local network.
1
by: Irrigho5 | last post by:
i have the open file function just need help with the copy file function and main Ask for a source filename and a target filename. Then copy the source file to the target file using the...
2
by: foss | last post by:
hi all, I am not able to copy file from a directory in the server to another directory. Here, the source is outside the web root directory and the destination is inside the web root directory. ...
1
by: rajibdotnet | last post by:
Till Date, I find no solution to the problem below. Unable to copy file "obj\Debug\Tax2010.dll" to "bin\Tax2010.dll". The process cannot access the file 'bin\Tax2010.dll' because it is being used...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.