C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Move Files One system to another system


Posted Date: 16 Jun 2006    Resource Type: Articles    Category: .NET Framework
Author: maheswara rao mMember Level: Gold    
Rating: Points: 5



Introduction


Here am trying to show common used funtions these are useful in all application .

1 .Coping Files One Directory to Another(dufferent Systems)



Public Sub CopyDirectory(ByVal srcDir As String, ByVal dstDir As String)
Dim srcDirectory As IO.DirectoryInfo = New IO.DirectoryInfo(srcDir)
Dim fInfo As IO.FileInfo
Dim dirInfo As IO.DirectoryInfo
For Each fInfo In srcDirectory.GetFiles()
If Not IO.Directory.Exists(dstDir) Then IO.Directory.CreateDirectory(dstDir)
Try
fInfo.CopyTo(IO.Path.Combine(dstDir, fInfo.Name))
Catch ex As Exception
MsgBox(ex.message)
End Try
Application.DoEvents()
Next

For Each dirInfo In srcDirectory.GetDirectories()
Dim subDirectory As String = IO.Path.Combine(dstDir, dirInfo.Name)
Try
IO.Directory.CreateDirectory(subDirectory)
Catch ex As Exception
MsgBox(ex.message)
End Try
CopyDirectory(dirInfo.FullName, subDirectory)
Next

End Sub
Ex:
strSrc = Replace(Application.StartupPath, "bin", "") + "Upload"
strDst = "\\FC1\test"
CopyDirectory(strSrc, strDst)

2. Get all System Names from Active Directory



Dim entry As DirectoryEntry = New DirectoryEntry("LDAP://mainserver.com") ‘Active Directory Name
Dim mySearcher As DirectorySearcher = New DirectorySearcher(entry)
mySearcher.Filter = ("(objectClass=computer)")
For Each resEnt As SearchResult In mySearcher.FindAll
Dim strName As String
Dim position As Integer
position = resEnt.GetDirectoryEntry.Name.IndexOf("=")
strName = resEnt.GetDirectoryEntry.Name.Substring(position + 1)
cmbDstSys.Items.Add(strName)
Next
entry = Nothing

3. Copying a Selected File to a Specified folder



dlgOpen.ShowDialog()
srcPath1 = dlgOpen.FileName
Dim finfo As New FileInfo(srcPath1)
Dim dirInfo As New DirectoryInfo(Application.StartupPath & "\..\Upload\")
If (Not dirInfo.Exists) Then
dirInfo.Create()
End If
Dim fcheck As New FileInfo(Application.StartupPath & "\..\Upload\" & finfo.Name)
If (fcheck.Exists) Then
If (MsgBox("File already exist. Do u want to overwrite that file...", MsgBoxStyle.Information + MsgBoxStyle.YesNoCancel, "Conformation") = MsgBoxResult.Yes) Then
File.Copy(srcPath1, fcheck.FullName, True)
Else
Exit Sub
End If
Else
File.Copy(srcPath1, fcheck.FullName)
End If






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to write an XML doccument from database query
Previous Resource: Delegates in VB.NET
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use