This blog is about the dotnet.all types of codes,news about dotnet including asp.net,vb.net,c# and know about new dotnet technology.programing in asp.net,vb.net,c#, ajax, AJAX tech support for .net and discuss the new technology in dotnet.ncluding asp.net,vb.net,c# and know about new dotnet technology.programing in asp.net,vb.net,c#, ajax, AJAX tech support for .net and discuss the new technology in dotnet.asp.net programming,dot net programming,dotnet programs,dotnet source code,source code.

Free Hosting

Free Hosting

Friday, January 23, 2009

File Folder Hirerchy to XML(vb.net)

File Folder Hirerchy to XML(vb.net)

Version: VB.NET 2003
Compatibility: VB.NET 2003, VB 2005
Category: File Manipulation

This code generates an XML file in the given directory with contents same as Explorer hierarchy. It also displays the files size and change date including folders description like Number of files or folders.
It can be used when you want to make a CD/DVD with many number of files and this xml file helps to find out the files/folders snapshots in a single look.


Declarations:
Imports System.IO

Dim Trgt As StreamWriter
Dim T1 As Threading.Thread

'Place on Textbox and and button. Give the path of
'the root folder in textbox1 and click the button.

Code:
Sub CreateXMLPath()
Trgt = New StreamWriter(TextBox1.Text & "\index.xml")
Trgt.WriteLine(" ")
Trgt.WriteLine("")
Text = "Started"
Trgt.WriteLine("Ajay ")
Trgt.WriteLine("" & DateTime.Now & " ")
ScanFolder(TextBox1.Text)
Trgt.WriteLine("
")
Trgt.Close()
Text = "Completed"
End Sub
Sub ScanFolder(ByVal FldName As String)
'On Error GoTo NextSub
Dim S As String

Dim TotFiles, TotFolders, TotSize As Long
Dim sZ As Double
Dim Fld As New DirectoryInfo(FldName), Fl As FileInfo
Dim MainFld As New DirectoryInfo(FldName)
Trgt.WriteLine("")
For Each Fld In MainFld.GetDirectories
Text = "Scanning folder " & FldName
ScanFolder(Fld.FullName())
TotFolders += 1
Next
For Each Fl In MainFld.GetFiles
TotFiles += 1
S = Fl.FullName
If Fl.Name <> "index.xml" Then
sZ = Math.Round(Fl.Length / 1024, 2)
Trgt.WriteLine("")
TotSize += Fl.Length
End If
Next
Trgt.WriteLine("

")
Trgt.WriteLine("")
NextSub:
End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
T1 = New Threading.Thread(AddressOf CreateXMLPath)
T1.Start()
End Sub

'Replace the invalid charactes for XML with valid one

Function ParseXML(ByVal S As String) As String
S = S.Replace("&", "&")
S = S.Replace("'", "")
S = S.Replace("""", "")
Return S
End Function

0 comments:

dotnet(.Net) Project Source code Downloads and Tutorials

Email Subscrption



Enter your email address:

Delivered by FeedBurner

Feedburner Count

Blog Archive

Unique Visitor

Design by araba-cı | MoneyGenerator Blogger Template by GosuBlogger