SgDotNet
Singapore Professional .NET User Group -For Cool Developers

creating xml document with flexible path

rated by 0 users
This post has 7 Replies | 2 Followers

Top 100 Contributor
Posts 20
forlorn Posted: 09-01-2005 11:32 AM

I have a program that has a login form. Once the user logs in, a folder will be created in the root folder under the username. And in the program, the user will be able to create an xml document. How do I go about configuring the code below so that each xml document will be stored inside each user's respective folder instead of just hard coding?

Dim mywriter1 As System.Xml.XmlTextWriter

mywriter1 = New System.Xml.XmlTextWriter("C:\Inetpub\wwwroot\FYP\admin\monitorconfig.xml", System.Text.Encoding.UTF8)

Top 50 Contributor
Posts 94

Dim mywriter1 As System.Xml.XmlTextWriter
Dim userPath as String

userPath = ...whatevercodeyou used to create the folder and determine the filename ....

mywriter1 = New System.Xml.XmlTextWriter(userPath, System.Text.Encoding.UTF8)

If you think education is expensive - try ignorance!
Top 25 Contributor
Posts 176
 stw wrote:

Dim mywriter1 As System.Xml.XmlTextWriter
Dim userPath as String

userPath = ...whatevercodeyou used to create the folder and determine the filename ....

mywriter1 = New System.Xml.XmlTextWriter(userPath, System.Text.Encoding.UTF8)



:-D... that's trivial.
if you are talking about putting at some relative directory to the web apps's root, then Server.MapPath is probably what you are looking for.

regards,
choongseng
my development sketch book my personal blog
Top 10 Contributor
Posts 865

On another note:

Why are you doing this ? Your solution will have huge scaliability problems once your users number into the hundreds. Do not forget that you have to set each folders' attributes as well for security or other purposes and I forsee other problems --- Duplicate Folder names, Portability of Folders should hosting environment change, Granular Access Control, etc

A good Web Application doesnt try to create folders in any directories.

This may be a good time to go into Normalizations and Keys.

~Softwaremaker (BLOG) M. Twain: "I didn't have time to write a short letter, so I wrote a long one instead"

Top 100 Contributor
Posts 20

Anyway its part of my project requirement that creating folders according to users ought to be done. Hm it can't seems to work, can ya guys help?

*My login form codes

Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click

Dim cn As New OleDb.OleDbConnection

Dim cm As New OleDb.OleDbCommand

Dim dr As OleDb.OleDbDataReader

Dim username As String = txtusername.Text

Dim password As String = txtpassword.Text

Try

cn.ConnectionString = ConfigurationSettings.AppSettings("ConnectionString")

cn.Open()

cm.Connection = cn

cm.CommandText = "Select * From admin where username='" & username & "' and password='" & password & "'"

dr = cm.ExecuteReader()

'dr.Read()

If dr.HasRows Then

System.Web.Security.FormsAuthentication.RedirectFromLoginPage(username, False)

If Directory.Exists(Server.MapPath(username)) = False Then

' creates the directory

Directory.CreateDirectory(Server.MapPath(username))

End If

Response.Redirect("http://localhost/FYP/frmabout.aspx?Username=" + txtusername.Text)

Else

lblerror.Text = "Incorrect username or password!"

End If

Catch ex As Exception

lblerror.Text = ex.Message

End Try

End Sub

* I want to configure the xml document path to be created in the user's folder

Dim mywriter1 As System.Xml.XmlTextWriter

mywriter1 = New System.Xml.XmlTextWriter("C:\Inetpub\wwwroot\FYP\admin\monitorconfig.xml", System.Text.Encoding.UTF8)

Top 10 Contributor
Posts 865
It would be really helpful if you can tell us the exception or else how are we going to know where it went wrong (db ? creating folder permissions ? hosting ? etc)

~Softwaremaker (BLOG) M. Twain: "I didn't have time to write a short letter, so I wrote a long one instead"

Top 100 Contributor
Posts 20

Erm nothing is wrong. I only want to know how do I actually configure the below lines of code so that the xml file would be created in the user's folder. Thanks.

Dim mywriter1 As System.Xml.XmlTextWriter

mywriter1 = New System.Xml.XmlTextWriter("C:\Inetpub\wwwroot\FYP\admin\monitorconfig.xml", System.Text.Encoding.UTF8)

Top 25 Contributor
Posts 176
 forlorn wrote:

Erm nothing is wrong. I only want to know how do I actually configure the below lines of code so that the xml file would be created in the user's folder. Thanks.

Dim mywriter1 As System.Xml.XmlTextWriter

mywriter1 = New System.Xml.XmlTextWriter("C:\Inetpub\wwwroot\FYP\admin\monitorconfig.xml", System.Text.Encoding.UTF8)



hmm... as what stw mentioned...

mywriter1 = New System.Xml.XmlTextWriter("C:\Inetpub\wwwroot\FYP\" & username & "\monitorconfig.xml", System.Text.Encoding.UTF8)

are you saying some thing as simple as above?

regards,
choongseng


my development sketch book my personal blog
Page 1 of 1 (8 items) | RSS
Copyright SgDotNet 2004-2008
Powered by Community Server (Commercial Edition), by Telligent Systems