Re: Files in an ASP.Net page

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Lars-Inge Tønnessen (http://emailme.larsinge.com)
Date: 03/17/04


Date: Wed, 17 Mar 2004 19:20:20 +0100

I have now implemented an working example in ASP.NET that XML serializes
your Variables class. Please note your have to set write access for the IIS
in the file system. Don't forget to set the file path where you want the XML
file. Default path is "C:\Windows\system32\".

My example page has a button with a click hander. When I click the button it
serializes lots of data in your Variables class.

package XMLSeriJSharp;

import System.Collections.*;
import System.ComponentModel.*;
import System.Data.*;
import System.Drawing.*;
import System.Web.*;
import System.Web.SessionState.*;
import System.Web.UI.*;
import System.Web.UI.WebControls.*;
import System.Web.UI.HtmlControls.*;

/** @attribute System.SerializableAttribute() */
public class Variables //Internal class for XML Serializing of class members
for Postback.
{
    public Variables() //Variables Default Public Constructor.
    {
    }

    private int intAdded; //Rows Added to the Database by AdapterPost[Add]
method.
    private boolean boolBinding; //If False, then no binding and don't load
a new row.
    private String strConnection; //Connection String.
    private String gstrDataBaseName; //Database Name.
    private String strDelete; //Delect SQL Instruction.
    private int intDeleted; //Rows Delete from the Database by
AdapterPost[Delete] method.
    private int intDeletedKeys; //Items deleted from disconnected
recordset.s
    private String strDeletedKeys; //Where list keys of Items deleted from
disconnecte recordset.
    private String strErrorMessage; //Last Error message
    private int intIdentitySeed; //Identity Seed.
    private String strIdentitySeed; //Identity Column Name.
    private String strInsert; //Insert string.
    private boolean boolIOStatus; //Read write Status: True=Success,
False=Error or Failure.
    private String strOwnerName; //Owner's name.
    private String strOwnerPassword; //Owner's Password.
    private int intRecordCount; //Record Count
    private int intRowPosition; //Current Position in the Table.
    private String strSchema; //Schema this database (for DB2).
    private String strSelect; //Original Select Statement.
    private String strStoredProcedureCursor; //Cursor Stored Procedure name.
    private String strStoredProcedureDelete; //Delete Stored Procedure name.
    private String strStoredProcedureInsert; //Insert Stored Procedure name.
    private String strStoredProcedureSelect; //Select Stored Procedure name.
    private String strStoredProcedureUpdate; //Update Stored Procedure name.
    private int intTotalFields; //Total Fields in a Row.
    private String strUpdate; //Update String.
    private int intUpdated; //Rows Updated in the Database by
AdapterPost[Update] method.
    private int intUpdateMode; //Mode: 0=Both. 1=Database Only. 2=Adapter
Only.

    /** @property */
    public void set_Added( int ad )
    {
        this.intAdded = ad;
    }

    /** @property */
    public int get_Added( )
    {
        return this.intAdded;
    }

    /** @property */
    public void set_Binding( boolean bind )
    {
        this.boolBinding = bind;
    }

    /** @property */
    public boolean get_Binding( )
    {
        return this.boolBinding;
    }

    /** @property */
    public void set_Connection( String con )
    {
        this.strConnection = con;
    }

    /** @property */
    public String get_Connection( )
    {
        return this.strConnection;
    }

    /** @property */
    public void set_DataBaseName( String db )
    {
        this.gstrDataBaseName = db;
    }

    /** @property */
    public String get_DataBaseName( )
    {
        return this.gstrDataBaseName;
     }

    /** @property */
    public void set_Delete( String del )
    {
        this.strDelete = del;
    }

    /** @property */
    public String get_Delete( )
    {
        return this.strDelete;
    }

    /** @property */
    public void set_DeletedA( int del )
    {
        this.intDeleted = del;
     }

    /* @property */
    public int get_DeletedA( )
    {
        return this.intDeleted;
    }

    /** @property */
    public void set_DeletedKeys( int keys )
    {
        this.intDeletedKeys = keys;
    }

    /** @property */
    public int get_DeletedKeys( )
    {
        return this.intDeletedKeys;
    }

    /** @property */
    public void set_strDeletedKeysA( String keys )
    {
        this.strDeletedKeys = keys;
    }

    /** @property */
    public String get_strDeletedKeysA( )
    {
        return this.strDeletedKeys;
    }

    /** @property */
    public void set_strErrorMessageA( String mess )
    {
        this.strErrorMessage = mess;
    }

    /** @property */
    public String get_strErrorMessageA( )
    {
        return this.strErrorMessage;
    }

    /** @property */
    public void set_IdentitySeedA( int seed )
    {
        this.intIdentitySeed = seed;
    }

    /** @property */
    public int get_IdentitySeedA( )
    {
        return this.intIdentitySeed;
    }

    /** @property */
    public void set_strInsertA( String insert )
    {
        this.strInsert = insert;
     }

    /** @property */
    public String get_strInsertA( )
   {
        return this.strInsert;
    }

    /** @property */
    public void set_boolIOStatusA( boolean io )
    {
        this.boolIOStatus = io;
    }

    /** @property */
    public boolean get_boolIOStatusA( )
    {
        return this.boolIOStatus;
    }

    /** @property */
    public void set_strOwnerNameA( String name )
    {
        this.strOwnerName = name;
    }

    /** @property */
    public String get_strOwnerNameA( )
    {
        return this.strOwnerName;
    }

    /** @property */
    public void set_strOwnerPasswordA( String pass )
    {
        this.strOwnerPassword = pass;
    }

    /** @property */
    public String get_strOwnerPasswordA( )
    {
        return this.strOwnerPassword;
    }

    /** @property */
    public void set_intRecordCountA( int count )
    {
        this.intRecordCount = count;
    }

    /** @property */
    public int get_intRecordCountA( )
    {
        return this.intRecordCount;
    }

    /** @property */
    public void set_intRowPositionA( int pos )
    {
        this.intRowPosition = pos;
    }

    /** @property */
    public int get_intRowPositionA( )
    {
        return this.intRowPosition;
    }

    /** @property */
    public void set_strSchemaA( String sch )
    {
        this.strSchema = sch;
    }

    /** @property */
    public String get_strSchemaA( )
    {
        return this.strSchema;
    }

    /** @property */
    public void set_strSelectA( String select )
    {
        this.strSelect = select;
    }

    /** @property */
    public String get_strSelectA( )
    {
        return this.strSelect;
    }

    /** @property */
    public void set_strStoredProcedureCursorA( String cursor )
    {
        this.strStoredProcedureCursor = cursor;
    }

    /** @property */
    public String get_strStoredProcedureCursorA( )
    {
        return this.strStoredProcedureCursor;
    }

    /** @property */
    public void set_strStoredProcedureInsertA( String insert )
    {
        this.strStoredProcedureInsert = insert;
    }

    /** @property */
    public String get_strStoredProcedureInsertA( )
    {
        return this.strStoredProcedureInsert;
    }

    /** @property */
    public void set_strStoredProcedureSelectA( String select )
    {
        this.strStoredProcedureSelect = select;
    }

    /** @property */
    public void set_strStoredProcedureDeleteA( String delete )
    {
        this.strStoredProcedureDelete = delete;
    }

    /** @property */
    public String get_strStoredProcedureDeleteA( )
    {
        return this.strStoredProcedureDelete;
    }

    /** @property */
    public String get_strStoredProcedureSelectA( )
    {
        return this.strStoredProcedureSelect;
    }

    /** @property */
    public void set_strStoredProcedureUpdateA( String update )
    {
        this.strStoredProcedureUpdate = update;
    }

    /** @property */
    public String get_strStoredProcedureUpdateA( )
    {
        return this.strStoredProcedureUpdate;
    }

    /** @property */
    public void set_intTotalFieldsA( int fileds )
    {
        this.intTotalFields = fileds;
    }

    /** @property */
    public int get_intTotalFieldsA( )
    {
        return this.intTotalFields;
    }

    /** @property */
    public void set_strUpdateA( String update )
    {
        this.strUpdate = update;
    }

    /** @property */
    public String get_strUpdateA( )
    {
        return this.strUpdate;
    }

    /** @property */
    public void set_intUpdatedA( int update )
    {
        this.intUpdated = update;
    }

    /** @property */
    public int get_intUpdatedA( )
    {
        return this.intUpdated;
    }

    /** @property */
    public void set_intUpdateModeA( int mode )
    {
        this.intUpdateMode = mode;
    }

    /** @property */
    public int get_intUpdateModeA( )
    {
        return this.intUpdateMode;
    }
} //End of XML Serializing Class

/**
* Summary description for WebForm1.
*/
public class WebForm1 extends System.Web.UI.Page
{
    protected System.Web.UI.WebControls.Label Label1;
    protected System.Web.UI.WebControls.Button Button1;
    private void Page_Load(Object sender, System.EventArgs e)
    {
        // Put user code to initialize the page here
    }
#region Web Form Designer generated code
    protected void OnInit(System.EventArgs e)
    {
        InitializeComponent();
        super.OnInit(e);
    }

    /**
    * Required method for Designer support - do not modify
    * the contents of this method with the code editor.
    */
    private void InitializeComponent()
    {
        this.Button1.add_Click( new
System.EventHandler(this.Button1_Click) );
        this.add_Load( new System.EventHandler(this.Page_Load) );
    }
#endregion
    private void Button1_Click (Object sender, System.EventArgs e)
    {
        Variables XML = new Variables();
        XML.set_Added( 1 );
        XML.set_Binding( true );
        XML.set_Connection( "a connection string" );
        XML.set_DataBaseName("\\\\localhost\\DB");
        XML.set_Delete( "delete me" );
        XML.set_DeletedA( 2323 );
        XML.set_DeletedKeys( 34 );
        XML.set_strErrorMessageA( "error message" );
        XML.set_IdentitySeedA( 234 );
        XML.set_strInsertA( "insert" );
        XML.set_boolIOStatusA( false );
        XML.set_strOwnerNameA( "Owner" );
        XML.set_strOwnerPasswordA( "your password" );
        XML.set_intRecordCountA( 345 );
        XML.set_intRecordCountA( 34 );
        XML.set_strSchemaA( "schema here" );
        XML.set_strSelectA( "Select * from tabel" );
        XML.set_strStoredProcedureCursorA( "cursor" );
        XML.set_strStoredProcedureDeleteA( "delete here" );
        XML.set_strStoredProcedureInsertA( "insert here" );
        XML.set_strStoredProcedureSelectA( "select here" );
        XML.set_strStoredProcedureUpdateA( "update here" );
        XML.set_intTotalFieldsA( 3445 );
        XML.set_strUpdateA( "update str" );
        XML.set_intUpdatedA( 22 );
        XML.set_intUpdateModeA( 2234 );

        System.Xml.Serialization.XmlSerializer serializer = new
System.Xml.Serialization.XmlSerializer( XML.GetType() );

        System.IO.Stream stream = new
System.IO.FileStream("C:\\Inetpub\\wwwroot\\XMLSeriJSharp\\file.xml",System.
IO.FileMode.Create );

        serializer.Serialize( stream, XML );

        stream.Flush();
        stream.Close();
    }
}

Lars-Inge Tønnessen
www.larsinge.com



Relevant Pages

  • Re: Arrays
    ... >public class collect{ ... > public int Limit; ... > public void setRegistrationNumber{ ... > public String getRegistrationNumber() { ...
    (comp.lang.java.help)
  • Re: Arrays
    ... public class collect{ ... public int Limit; ... public void setRegistrationNumber{ ... public String getRegistrationNumber() { ...
    (comp.lang.java.help)
  • Re: XML serialization of an Hashtable 2
    ... the same code doing a google search - ... > public string familyname; ... > public void AddNew() ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: XML serialization of an Hashtable 2
    ... >> public string familyname; ... public void AddNew() ... >>> public class Event ... There was an error reflecting type ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: dynamic tool tip text
    ... public class CustomTextField extends JTextField { ... public String getToolTipText{ ... public void mouseEntered{ ...
    (comp.lang.java.programmer)