Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update XML record

Status
Not open for further replies.

Reinout

IS-IT--Management
Feb 22, 2004
48
BE
I'd like to update my XML file. At least 1 field from 1 record. Is this possible without saving the whole file all over?
This is my code :

Code:
private sub getPassword_Click(obj as Object, e as EventArgs) 

    if not (Page.IsValid) Then
        Msg.Text = "Some required fields are invalid."
        return    
    end if

    'Check if e-mail is in the database, so if user exists
    dim cmd as String = "UserEmail='" + UserEmail.Value + "'"
    dim ds as DataSet = new DataSet()
    dim fs as FileStream = new FileStream(Server.MapPath(userFile),FileMode.Open,FileAccess.Read)
    dim reader as StreamReader = new StreamReader(fs)

    ds.ReadXml(reader)
    fs.Close()
    dim users as DataTable = ds.Tables(0)
    dim matches as DataRow() = users.Select(cmd)

    dim DBNull As Object = Convert.DBNull

    if not (matches Is Nothing) AND matches.Length > 0 Then
        'If user exists :
	dim newPassword as string
	newPassword = GeneratePassword(8)
	dim test as boolean
        'send mail to users with their new password
        dim objEmail as New MailMessage()
	objEmail.To = UserEmail.Value
	objEmail.From = "test@test.be"
	objEmail.Subject = "Test mail"
	objEmail.Body = "newPassword"
        SmtpMail.SmtpServer = "mail-out.pandora.be"
        try
            SmtpMail.Send(objEmail)
            Response.Write("Your E-mail has been sent successfully - Thank You")
 	    test = True
        catch exc as Exception
            Response.Write("Send failure: " + exc.ToString())
	    test = False
        End Try
	
	if test Then
            'if the mail was sent, add the new password to the xml file
	    dim row as Datarow = matches(0)

	    ?????????????????????????????

	else
	end if

        Response.Redirect("../Logon.aspx")    
    else
	'If user-mail is not in the xml-file 	
	Msg.Text = "E-mail does not exist."
    end if

end sub
 
I finally found it. For people that are interested :

Code:
            Dim objdata as Dataset = New DataSet()
							 
    	    dim fs2 as FileStream = new FileStream(Server.MapPath(userFile),FileMode.Open,FileAccess.Read)
	    dim reader2 as StreamReader = new StreamReader(fs2)
	    objdata.ReadXml(reader2)
	    fs2.Close()
					
            objdata.Tables(0).DefaultView.RowFilter="UserEmail='" & UserEmail.Value & "'"

            If objdata.Tables(0).DefaultView.Count>0 Then
              objdata.Tables(0).Rows(0).Item("UserPassword")=newPassword
              fs2 = new FileStream(Server.MapPath(userFile),FileMode.Create,FileAccess.ReadWrite)
              dim writer as StreamWriter = new StreamWriter(fs2)
              objdata.WriteXml(writer)
              writer.Close()
              fs2.Close()
            End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top