Click here to Skip to main content
15,884,473 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: How do I change this code using Inheritance? Pin
Richard MacCutchan13-Dec-19 0:00
mveRichard MacCutchan13-Dec-19 0:00 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede13-Dec-19 0:25
Marc Hede13-Dec-19 0:25 
GeneralRe: How do I change this code using Inheritance? Pin
Richard MacCutchan13-Dec-19 0:44
mveRichard MacCutchan13-Dec-19 0:44 
QuestionHistogram in Asp.net using canvas js Pin
pooja thombare11-Dec-19 20:47
pooja thombare11-Dec-19 20:47 
AnswerRe: Histogram in Asp.net using canvas js Pin
Richard MacCutchan11-Dec-19 21:16
mveRichard MacCutchan11-Dec-19 21:16 
JokeRe: Histogram in Asp.net using canvas js Pin
Richard Deeming12-Dec-19 12:54
mveRichard Deeming12-Dec-19 12:54 
AnswerRe: Histogram in Asp.net using canvas js Pin
phil.o11-Dec-19 23:05
professionalphil.o11-Dec-19 23:05 
QuestionI can´t get any output from XML and Binary. Pin
Marc Hede8-Dec-19 3:51
Marc Hede8-Dec-19 3:51 
I have been trying to experiment with XML and Binary files.
I did so by re-writing a code I made in an ASP NET Web Application.

Keycard.cs
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace Keycard
{
    [Serializable()]
    public class Keycard : ISerializable
    {
        protected string name;
        protected int mykey;

        public Keycard(string name, int mykey)
        {
            this.Name = name;
            this.Mykey = mykey;
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public int Mykey
        {
            get { return mykey; }
            set { mykey = value; }
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {

            info.AddValue("Name", name);
            info.AddValue("Keynumber", mykey);
  
        }
        public Keycard(SerializationInfo info, StreamingContext context)
        {
            Name = (string)info.GetValue("Name", typeof(string));
            Mykey = (int)info.GetValue("Keynumber", typeof(int));
        }

        public override string ToString()
        {
            return "Name: " + name + " ---- " + " Keynumber: " + mykey;
        }
    }
}


index.aspx.cs
C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Xml.Serialization;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace Keycard
{
    public partial class Index : System.Web.UI.Page
    {
        public void Main(string[] args)
        {
            Keycard d1 = new Keycard("John", 102030);

            Stream stream = File.Open("KeycardData.dat",
                FileMode.Create);

            BinaryFormatter bf = new BinaryFormatter();

            bf.Serialize(stream, d1);
            stream.Close();

            d1 = null;

            stream = File.Open("KeycardData.dat", FileMode.Open);

            bf = new BinaryFormatter();

            d1 = (Keycard)bf.Deserialize(stream);
            stream.Close();
            Console.WriteLine(d1.ToString());

            XmlSerializer serializer = new XmlSerializer(typeof(Keycard));

            using(TextWriter tw = new StreamWriter(@"L\C#\keycards.xml"))
            {
                serializer.Serialize(tw, d1);
            }

            d1 = null;

            XmlSerializer deserializer = new XmlSerializer(typeof(Keycard));
            TextReader reader = new StreamReader(@"L\C#\keycards.xml");
            object obj = deserializer.Deserialize(reader);
            d1 = (Keycard)obj;
            reader.Close();
            Console.WriteLine(d1.ToString());
        }

    }
}


I am not getting any error messages at all, and when I press IIS Express, I get my index page, which just has a listbox, but of course there is no data in that listbox.

I can not get any data output, and it does not save any XML file in the folder that I specified. I think the reason might be that I am trying to use this code in a Web Application, but I have never worked with any other types of projects, so I am not sure what I should use instead.

Do you guys think this is the reason? Or could there be another reason as to why I am not getting my data to show up?
As I said, I am getting new error messages, so I have no idea where the problem comes from.
AnswerRe: I can´t get any output from XML and Binary. Pin
Richard MacCutchan8-Dec-19 5:15
mveRichard MacCutchan8-Dec-19 5:15 
GeneralRe: I can´t get any output from XML and Binary. Pin
Marc Hede8-Dec-19 7:17
Marc Hede8-Dec-19 7:17 
GeneralRe: I can´t get any output from XML and Binary. Pin
Richard MacCutchan8-Dec-19 21:51
mveRichard MacCutchan8-Dec-19 21:51 
QuestionExample Needed Pin
Mycroft Holmes30-Nov-19 12:02
professionalMycroft Holmes30-Nov-19 12:02 
QuestionRe: Example Needed Pin
Maciej Los3-Dec-19 1:53
mveMaciej Los3-Dec-19 1:53 
QuestionProblem with Using Directive Pin
Dawud Ahmad29-Nov-19 17:00
Dawud Ahmad29-Nov-19 17:00 
AnswerRe: Problem with Using Directive Pin
phil.o29-Nov-19 22:19
professionalphil.o29-Nov-19 22:19 
SuggestionRe: Problem with Using Directive Pin
Richard Deeming3-Dec-19 0:47
mveRichard Deeming3-Dec-19 0:47 
QuestionShould I begin with razor pages or mvc? Pin
Dawud Ahmad29-Nov-19 6:29
Dawud Ahmad29-Nov-19 6:29 
AnswerRe: Should I begin with razor pages or mvc? Pin
Richard MacCutchan29-Nov-19 7:27
mveRichard MacCutchan29-Nov-19 7:27 
AnswerRe: Should I begin with razor pages or mvc? Pin
Richard Deeming29-Nov-19 8:01
mveRichard Deeming29-Nov-19 8:01 
QuestionNewbie here. Why is my array list not working? Pin
Marc Hede28-Nov-19 0:31
Marc Hede28-Nov-19 0:31 
AnswerRe: Newbie here. Why is my array list not working? Pin
phil.o28-Nov-19 0:41
professionalphil.o28-Nov-19 0:41 
AnswerRe: Newbie here. Why is my array list not working? Pin
Richard Deeming28-Nov-19 1:24
mveRichard Deeming28-Nov-19 1:24 
GeneralRe: Newbie here. Why is my array list not working? Pin
Marc Hede28-Nov-19 6:14
Marc Hede28-Nov-19 6:14 
GeneralRe: Newbie here. Why is my array list not working? Pin
Richard Deeming28-Nov-19 6:39
mveRichard Deeming28-Nov-19 6:39 
GeneralRe: Newbie here. Why is my array list not working? Pin
Marc Hede28-Nov-19 9:09
Marc Hede28-Nov-19 9:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.