Click here to Skip to main content
14,739,966 members
Home » Discussions » ASP.NET
   

ASP.NET

 
GeneralRe: How do I change this code using Inheritance? Pin
Richard MacCutchan13-Dec-19 1:00
mveRichard MacCutchan13-Dec-19 1:00 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede13-Dec-19 1:25
MemberMarc Hede13-Dec-19 1:25 
GeneralRe: How do I change this code using Inheritance? Pin
Richard MacCutchan13-Dec-19 1:44
mveRichard MacCutchan13-Dec-19 1:44 
QuestionHistogram in Asp.net using canvas js Pin
pooja thombare11-Dec-19 21:47
Memberpooja thombare11-Dec-19 21:47 
AnswerRe: Histogram in Asp.net using canvas js Pin
Richard MacCutchan11-Dec-19 22:16
mveRichard MacCutchan11-Dec-19 22:16 
JokeRe: Histogram in Asp.net using canvas js Pin
Richard Deeming12-Dec-19 13:54
mveRichard Deeming12-Dec-19 13:54 
AnswerRe: Histogram in Asp.net using canvas js Pin
phil.o12-Dec-19 0:05
mvephil.o12-Dec-19 0:05 
QuestionI can´t get any output from XML and Binary. Pin
Marc Hede8-Dec-19 4:51
MemberMarc Hede8-Dec-19 4: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
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
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 6:15
mveRichard MacCutchan8-Dec-19 6:15 
GeneralRe: I can´t get any output from XML and Binary. Pin
Marc Hede8-Dec-19 8:17
MemberMarc Hede8-Dec-19 8:17 
GeneralRe: I can´t get any output from XML and Binary. Pin
Richard MacCutchan8-Dec-19 22:51
mveRichard MacCutchan8-Dec-19 22:51 
QuestionExample Needed Pin
Mycroft Holmes30-Nov-19 13:02
professionalMycroft Holmes30-Nov-19 13:02 
QuestionRe: Example Needed Pin
Maciej Los3-Dec-19 2:53
mveMaciej Los3-Dec-19 2:53 
QuestionProblem with Using Directive Pin
Dawud Ahmad29-Nov-19 18:00
MemberDawud Ahmad29-Nov-19 18:00 
AnswerRe: Problem with Using Directive Pin
phil.o29-Nov-19 23:19
mvephil.o29-Nov-19 23:19 
SuggestionRe: Problem with Using Directive Pin
Richard Deeming3-Dec-19 1:47
mveRichard Deeming3-Dec-19 1:47 
QuestionShould I begin with razor pages or mvc? Pin
Dawud Ahmad29-Nov-19 7:29
MemberDawud Ahmad29-Nov-19 7:29 
AnswerRe: Should I begin with razor pages or mvc? Pin
Richard MacCutchan29-Nov-19 8:27
mveRichard MacCutchan29-Nov-19 8:27 
AnswerRe: Should I begin with razor pages or mvc? Pin
Richard Deeming29-Nov-19 9:01
mveRichard Deeming29-Nov-19 9:01 
QuestionNewbie here. Why is my array list not working? Pin
Marc Hede28-Nov-19 1:31
MemberMarc Hede28-Nov-19 1:31 
AnswerRe: Newbie here. Why is my array list not working? Pin
phil.o28-Nov-19 1:41
mvephil.o28-Nov-19 1:41 
AnswerRe: Newbie here. Why is my array list not working? Pin
Richard Deeming28-Nov-19 2:24
mveRichard Deeming28-Nov-19 2:24 
GeneralRe: Newbie here. Why is my array list not working? Pin
Marc Hede28-Nov-19 7:14
MemberMarc Hede28-Nov-19 7:14 
GeneralRe: Newbie here. Why is my array list not working? Pin
Richard Deeming28-Nov-19 7:39
mveRichard Deeming28-Nov-19 7:39 
GeneralRe: Newbie here. Why is my array list not working? Pin
Marc Hede28-Nov-19 10:09
MemberMarc Hede28-Nov-19 10: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.