I found this on the web a few years ago. I do not remember where.
Private Sub CopyDirectory(ByVal SourcePath As String, ByVal DestPath As String, _
Optional ByVal Overwrite As Boolean = False)
Dim SourceDir As DirectoryInfo = New DirectoryInfo(SourcePath)
Dim DestDir As DirectoryInfo = New DirectoryInfo(DestPath)
' the source directory must exist, otherwise throw an exception
If SourceDir.Exists Then
' if destination SubDir's parent SubDir does not exist throw an exception
If Not DestDir.Parent.Exists Then
Throw New DirectoryNotFoundException _
("Destination directory does not exist: " + DestDir.Parent.FullName)
If Not DestDir.Exists Then
' copy all the files of the current directory
Dim ChildFile As FileInfo
For Each ChildFile In SourceDir.GetFiles()
If Overwrite Then
ChildFile.CopyTo(Path.Combine(DestDir.FullName, ChildFile.Name), True)
' if Overwrite = false, copy the file only if it does not exist
' this is done to avoid an IOException if a file already exists
' this way the other files can be copied anyway...
If Not File.Exists(Path.Combine(DestDir.FullName, ChildFile.Name)) Then
ChildFile.CopyTo(Path.Combine(DestDir.FullName, ChildFile.Name), _
' copy all the sub-directories by recursively calling this same routine
Dim SubDir As DirectoryInfo
For Each SubDir In SourceDir.GetDirectories()
CopyDirectory(SubDir.FullName, Path.Combine(DestDir.FullName, SubDir.Name), Overwrite)
Throw New DirectoryNotFoundException("Source directory does not exist: " + SourceDir.FullName)
The recursive call is a bit confusing but this has copied my list of directories every night for at least two years.
Should solve your porbelm also.
Is it possible to create access users from Vb.net. The company I work for has an application in Access 2003 with a SQL server back end. To log in to the application you have to be a user in SQL server and a user in access with the same password. We are constantly adding new users to the application. I want to create a VB.net application that creates SQL server users and Access users in one place. I was wondering if this is possible. Any ideas or commends or code would be appreciated.
I have been trying to connect to the mdw file to insert the users but no luck there. Thanks for the idea for the com object but I still would need the VBA code. I will play with it and if I figure out anything ill post the code. Meanwhile if any one can throw any code my way I would appreciate it. Thanks Johny now I have a staring point.
Hi! I want to know how can i open files of any type with appropriate programs in vb.
(Say to open html with internet explorer and frm file with vb etc)
The Shell command in vb is useful in launching only EXEs. But I am not able to open files of other type.
For example my vb code should open "c:\abc\test.txt" with notepad.
Secondly I want to how long my system continues to be in idle state.The screen saver is launched only when system remains idle for a particular time.
And I need to retrieve the idle time of system using my code.How is it possible?
I have a crystal report with 3 parameters, XYZ, Version, Other and I am trying to pass values via VB.Net to this report. It is no problem passing one but any more than that, it does not seem to work. The problem is that it the last parameter holds the value and the others are blank. What am I doing wrong. This is driving me crazy. Here is my code.
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim strReportPath As String = "C:\temp\report1.rpt"
'Load Crystal Report's rpt file
Dim cr As New CrystalDecisions.CrystalReports.Engine.ReportDocument
''Declare the parameter related objects
Dim param1Fields As New CrystalDecisions.Shared.ParameterFields
Dim param1Field As New CrystalDecisions.Shared.ParameterField
Dim param1Range As New CrystalDecisions.Shared.ParameterDiscreteValue
Dim param2Fields As New CrystalDecisions.Shared.ParameterFields
Dim param2Field As New CrystalDecisions.Shared.ParameterField
Dim param2Range As New CrystalDecisions.Shared.ParameterDiscreteValue
Dim param3Fields As New CrystalDecisions.Shared.ParameterFields
Dim param3Field As New CrystalDecisions.Shared.ParameterField
Dim param3Range As New CrystalDecisions.Shared.ParameterDiscreteValue
Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
CrystalReportViewer1.ReportSource = strReportPath
'Set the CrystalReportViewer's apperance and set the ReportSource
CrystalReportViewer1.ShowRefreshButton = False
CrystalReportViewer1.ShowCloseButton = False
CrystalReportViewer1.ShowGroupTreeButton = False
Catch ex As Exception
Can anyone point me in the right direction to write a ‘cluster aware service’.
I have written a service in VB.NET all works very well but my client said that the service must be cluster aware, as it will be running on a cluster of servers.