|
Hey,
Using the FolderBrowserDialog i select a folder. From here i want to recurse through this folder and add it (and all its subfolders and files) to an XML file so it can then populate a treeeview.
I am having trouble recursing the Folders and files in to the correct xml nodes during the recursion.
I am using structure:
<category>
<name></name>
<file>
<name></name>
<path></path>
</file>
</category>
And for Sub Folders
<category>
<name></name>
<file>
<name></name>
<path></path>
</file>
<category>
<name></name>
<file>
<name></name>
<path></path>
</file>
</category>
</category>
Any help or tip or links would be very helpful
thanks for your time
Chris
|
|
|
|
|
hi, This is a particularly easy problem to solve as a small recursive function will do all the work for you.
The best way I could think to do this was to derive a class from XmlTextWriter - in my case I named it XmlFileSystemWriter. The purpose here is to add a method that will write out a directory recursively, to the Xml, in the format you want.
Here's what I ended up with:
using System;
using System.IO;
using System.Xml;
using System.Text;
namespace TestApp
{
public class XmlFileSystemWriter : XmlTextWriter
{
public XmlFileSystemWriter(TextWriter w) : base(w)
{
}
public XmlFileSystemWriter(string fileName, Encoding encoding) : base(fileName, encoding)
{
}
public XmlFileSystemWriter(Stream stream, Encoding encoding) : base(stream, encoding)
{
}
public void WriteFileSystemInfo(DirectoryInfo baseDir)
{
this.WriteStartElement("fileSystemInfo");
this.WriteDirectory(baseDir);
this.WriteEndElement();
}
private void WriteFile(FileInfo info)
{
this.WriteStartElement("file");
this.WriteElementString("name",info.Name);
this.WriteElementString("path",info.FullName);
this.WriteEndElement();
}
private void WriteDirectory(DirectoryInfo info)
{
this.WriteStartElement("category");
this.WriteElementString("name",info.Name);
foreach(DirectoryInfo subDir in info.GetDirectories())
WriteDirectory(subDir);
foreach(FileInfo file in info.GetFiles())
WriteFile(file);
this.WriteEndElement();
}
}
}
Usage should be simple enough to work out:
<br />
DirectoryInfo di = new DirectoryInfo("C:\\yourdirectory");<br />
XmlFileSystemWriter w = new XmlFileSystemWriter(Console.Out);
w.Formatting = Formatting.Indent;<br />
w.WriteFileSystemInfo(di);<br />
I have provided all three constructors for you so you can use a TextWriter, write to a specified file, or to a specified Stream - have a play with the above and post back if you have any problems.
|
|
|
|
|
Hey Jamie,
Your help proved real usefull, I have got it working writing dir structure to xml. I changed my schema though to:
<category label="Directory Name">
<file>
<name>Test1</name>
<path>C:\Test1</path>
<file>
<category label="Sub Category">
<file>
<name>Test2</name>
<path>C:\Test2</path>
<file>
</category>
</category>
The only problems i seem to be having now is recursing through the XML document to add nodes to tree view so the category attributes are the Parent and child tree nodes and the <file> <name> information is the files within either nodes.
So for example from the above XML
Directory Name
- Sub Category
- Test2
- Test1
Any help would also be appreciated on this matter, thanks very much for your effort so far.
Kind regards
Chris
|
|
|
|
|
Solved my problem, thanks for the help
chris
|
|
|
|
|
Hi All,
I am abt to trying filling PDF forms using VB.NET in DOT NET.
Would you please anybody let me know Saving ,Deleting ,Editing PDF forms in DOT NET if anybody has contributed on this.Please send me ur suggestion ASAP
Regards
Anurag
Anurag
|
|
|
|
|
There are a number of components you can buy in to do this, some of the vendors even advertise on CodeProject, so it shouldn't be too hard to search for things to do this.
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
Can you get something deep besides this...Getting Components from third party and build ur own...
Regards
Anurag
|
|
|
|
|
|
But if you wanted to build your own, the documentation and SDK's to support what you want to do can be found at http://developer.adobe.com, for the nominal fee of $195.00 US, of course. Other than that, you'll have to search the Open Source sites, like SourceForge, for similar projects.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi
I want to develop one application in VB.NET (ASP.NET Web Application). Now I want to use some of the functions which are in my DLL that I developed in C++.
Plz any one can guid me how to include the DLL or what is the code to include DLL into VB.NET ?
Pls help me dear ?
Regards
Mike
|
|
|
|
|
|
couldn't you just add a reference to the dll and then use it from there??
|
|
|
|
|
but there is no dll file in the source, am i missing something? all i see is a .cs which is a text based file.....i am a little ignorant to the subject of dll files, so if i am missing something please let me know, but i dont see a dll file to reference too. i also do not have a c# compiler in my vs.net
|
|
|
|
|
the C# compiler is freely available. It comes with the .NET SDK which was quite probably installed with VS - if not you should be able to find it on the Microsoft web site. Look for a file on your system called csc.exe. If there is only one cs file it is quite easy to compile it into an assembly (DLLs are properly called assemblies in .NET)
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
the compile was successful, later tonight i will tell yall if it works =)
|
|
|
|
|
Hi,
I am trying to use the propertygrid as a user interface. I have currently only two issues left. The first one is how can I store the value of a listbox in a property. I am using the propertybag as described in "bending the propertygrid". As far as I can see I can only store the text of the listbox. I need both a the one is the key in my database and the other the sensible text.
Secondly I have a couple of multiline textboxes, for instance for some additional information about a person. As the propertygrid is only single line I was thinking of using the description box to display the full text. For this I would need to be able to change the description and set this equal to the information that was just entered at run time. Is this possible or are there some other solutions to tackle this problem?
Any help would be appreciated
Cheers
David J
|
|
|
|
|
Dim PKCalls As DataTable = DirectCast(Session("GetPKCallS"), DataTable)
PKCalls = New DataTable()
Dim sc As New PK.BusinessLogicLayer.Consumer()
Dim tDay As Integer
Dim tCall As Integer
Dim DD As String
Dim CallActivity As String
tDay = Integer.Parse(txtPast.Text)
tCall = Integer.Parse(txtCall.Text)
DD = Today.AddDays(-tDay)
CallActivity = Today.AddDays(-tCall)
PKCalls = sc.GetPKCallSheet(txtGender.Text, txtRace.Text, lblUpDOB.Text, lblLowDOB.Text, ddlSite.SelectedItem.Value, DD, CallActivity)
Session("GetPKCallS") = PKCalls
Dim cr As New ReportDocument()
Dim cx As New ExportOptions()
cr.Load("path to Crystal Report file")
cr.SetDataSource(Session("GetPKCallS"))
Dim N As String
N = "CallSheets" & Session("userOffice") & Now & ".rpt.PDF"
N = Replace(N, Chr(32), "")
N = Replace(N, ":", "")
N = Replace(N, "/", "")
cr.SaveAs("filepath to destination" & N, ReportFileFormat.VSNetFileFormat)
***********************************
*Given the above code, I am able to send this file to where I want it. When
I try to open the file I get this:
"Adobe Reader could not open 'Name.rpt.PDF' because it is either not a supported file type or because the file has been corrupted"
*************************************
Please help, any examples are much appreciated.
Thank you.
|
|
|
|
|
What CrystalReports is writing to your file is not a valid .PDF format. The version of CrystalReports that comes with Visual Studio, apparently, doesn't support .PDF. It looks like you'll have to upgrade to the full version of CR from BusinessObjects.com.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Can anybody tell me how I can append to a string using a ‘For Each’ loop?
Here is my loop:
For Each File In Dir.GetFiles("*.lnk")<br />
...<br />
TheString = "Some Data" & Variable<br />
Next<br />
<br />
FinalString =
In the example each loop changes ‘Variable’ and I want to, on the first loop, set ‘FinalString’ equal to ‘TheString’ and then on each loop thereafter I want to append ‘TheString’ to ‘FinalString’
Thanks
Brad
|
|
|
|
|
Use a StringBuilder . You'll find it in the System.Text namespace.
Example using StringBuilder.Append[^]
1. Create the StringBuilder
2. Start the Loop
3. Append to the StringBuilder
4. Repeat 3 as necessary
5. Call ToString() on the StringBuilder to get at the string .
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
Thats perfect.
Thank you.
|
|
|
|
|
Hi, I use the following code when the form is load:
Dim cnnCat As New ADODB.Connection
Dim rstCat As New ADODB.Recordset
Dim strCatSql As String ' Hold an SQL statement.
Private Sub frmCategory_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' Combine the connection string and connect to database.
strConnection = strProvider & strDbPath
'MsgBox(strConnection)
cnnCat.Open(strConnection)
cnnCat.CursorLocation = ADODB.CursorLocationEnum.adUseClient
' Get the record from the table.
strCatSql = "SELECT * FROM tblCat"
rstCat.Open(strCatSql, cnnCat, _
ADODB.CursorTypeEnum.adOpenKeyset, _
ADODB.LockTypeEnum.adLockOptimistic)
With rstCat
If .RecordCount > 0 Then
' Populate the recordset.
.MoveFirst()
.MoveLast()
' Display the record on the form.
Call ReadRecord()
End If
End With
End Sub
And the following code to close the form:
Private Sub btnClose_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnClose.Click
' Prompt the user before close the form.
dlrUserAnswers = MessageBox.Show("Are you sure you want to close " & _
"Category form?", "Close Category", MessageBoxButtons.YesNo, _
MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
If dlrUserAnswers = DialogResult.Yes Then
' Close database connection.
rstCat.Close()
cnnCat.Close()
' Release the objects to free memory.
rstCat = Nothing
cnnCat = Nothing
' Close the form.
Me.Close()
End If
End Sub
But when I start the form again, it display an error message as below:
An unhandled exception of type 'System.NullReferenceException' occurred in NGOCRC-Document Management.exe
Additional information: Object reference not set to an instance of an object.
Does anyone know why this problem occure? and how to solve this problem?
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
On what line does the exception occur?
It looks like your HIDING the form, not destroying it and creating a new one. This would cause your two ADODB objects at the top of your code to be created once, and when destroyed by your Form close code, never created again. It's bad practice to use "global" objects like this. What your doing in your code is, apparently, when the form is opened creating and HOLDING ON TO database connections and resources and not releaseing them until the form closes. You should NOT do this. Database resources are expensive and should be opened, used, and then released as soon as possible, preferrably inside the same method.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
On what line does the exception occur?
This exception occure at the line that is bold:
Private Sub frmCategory_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' Combine the connection string and connect to database.
strConnection = strProvider & strDbPath
'MsgBox(strConnection)
cnnCat.Open(strConnection)
cnnCat.CursorLocation = ADODB.CursorLocationEnum.adUseClient
' Get the record from the table.
strCatSql = "SELECT * FROM tblCat"
rstCat.Open(strCatSql, cnnCat, _
ADODB.CursorTypeEnum.adOpenKeyset, _
ADODB.LockTypeEnum.adLockOptimistic)
' ... The below code are the same as the one that post before.
End Sub
Dave Kreskowiak wrote:
It looks like your HIDING the form, not destroying it and creating a new one
Because I was experience with VB6 I used to close the form by Unload Me . When I move to VB.NET I found Show , ShowDialog and Close method but I could not find Unload Me anymore. I think Close might override Unload Me statement. But after I change the close procedure as the code below (the bold code is the code that I block comment or delete from the procedure), the it is working whether I start and close and restart the form many time.
Private Sub btnClose_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnClose.Click
' Prompt the user before close the form.
dlrUserAnswers = MessageBox.Show("Are you sure you want to close " & _
"Category form?", "Close Category", MessageBoxButtons.YesNo, _
MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
If dlrUserAnswers = DialogResult.Yes Then
' Close database connection.
rstCat.Close()
cnnCat.Close()
' Release the objects to free memory.
'rstCat = Nothing
'cnnCat = Nothing
'' Close the form.
'Me.Close()
End If
End Sub
But one new problem come out when I try to add the record that is duplicate in the database. Whether I use Try Catch End Try to block an exception but I could not work around with the other function such as MoveNext , MovePrevious ... Do you have any idea about that?
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
Dave Kreskowiak wrote:
It's bad practice to use "global" objects like this. What your doing in your code is, apparently, when the form is opened creating and HOLDING ON TO database connections and resources and not releaseing them until the form closes. You should NOT do this. Database resources are expensive and should be opened, used, and then released as soon as possible, preferrably inside the same method.
Dave, I wonder about the code that I get it the first time before I customize it:
dim cnn as New ADODB.Connection
dim rst as New ADODB.Recordset
Privat Sub Form1_Load()
cnn.Open("Provider...;Data Source=...")
' Get the record from the table.
rst.Open("SELECT * FROM [TableName]", cnnCat)
' ...
' The code to check the record and put it on the form.
rst.Close
cnn.Close
rst=Nothing
cnn=Nothing
End Sub
The code that I wonder is the bold line:
rst.Close
cnn.Close
rst=Nothing
cnn=Nothing
I wonder: if i release the recordset and the connection, how about the code that I write for an Add new record button, Update, Delete, Move (previous, next, last, first)? Do I need to open it again? If Yes, then I have to open it again how about the record position? Does it remember the last position in the recordset? I really wonder about that, so that is the reason that I write a GLOBAL object. Could you give me some comment and correct it with a small sample code?
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|