Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

Events Between Web Forms

, 6 Jul 2007 CPOL
Raise Events Between Web Forms Using CallBacks or Ajax
Imports System.Web.Script.Services
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.IO




<ScriptService()> _
    Partial Public Class WSUsers
    Inherits System.Web.Services.WebService

    ''' <summary>
    ''' Adds a new user to the list
    ''' </summary>
    ''' <param name="Name">Name of the user</param>
    ''' <param name="Age">Age of the user</param>
    ''' <returns>A message</returns>
    <WebMethod(Description:="Add a new uer")> _
    <ScriptMethod()> _
    Public Function AddUser(ByVal Name As String, ByVal Age As Integer) As String

        'The data source
        Dim DS As New DataSet
        'Check if the file exists
        Dim file As New FileInfo(Server.MapPath(System.Web.HttpRuntime.AppDomainAppVirtualPath) & "/Data.xml")
        If Not file.Exists Then
            DS.Tables.Add("Users")
            DS.Tables("Users").Columns.Add("User Name", GetType(String))
            DS.Tables("Users").Columns.Add("Age", GetType(Integer))
        Else
            DS.ReadXml(file.FullName)
        End If
        'Add the new user
        Dim user As DataRow = DS.Tables("Users").NewRow
        user(0) = Name
        user(1) = Age
        DS.Tables("Users").Rows.Add(user)
        'write the DS to the file
        DS.WriteXml(file.FullName, XmlWriteMode.WriteSchema)

        Return "User:" & Name & " Age:" & Age.ToString & "    Added At:" & Date.Now

    End Function

End Class


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Pramirez
Web Developer
Mexico Mexico
I am Pedro Ramirez from mexico, work for www.sciodev.com, the company is located in Mexico, we do outsourcing and nearshore development, we are focused on SaaS nearshore development, I started with VB.Net, but now I am ambidextrous using VB.Net or C#.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150224.1 | Last Updated 6 Jul 2007
Article Copyright 2007 by Pramirez
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid