.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson
Post New Web Links

Object Serialization

Posted By:      Posted Date: October 14, 2010    Points: 0   Category :ASP.Net

Class 1
public class Class1
    private int _id;

    public int Id
        get { return _id; }
        set { _id = value; }
    private string _name;

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

Default Page

ob.Name = TextBox1.Text;
        ob.Id = Convert.ToInt32(TextBox2.Text);
        SqlConnection con = new SqlConnection(connstr);
        SqlCommand cmd = new SqlCommand("insert into user1 values(@name,@id)", con);
        cmd.Parameters.AddWithValue("@name", ob.Name);
        cmd.Parameters.AddWithValue("@id", ob.Id);

Private Method Writeperson when i trying to use xmlserailizer it's saying it cannot be acces due to its proctection level

private void WritePerson()
        XmlSerializer ob1 = new XmlSerializer();
        StreamWriter sw = new StreamWriter(Server.MapPath("person.xml"));
        ob1.Serialize(sw, ob);

what i m doing wrong can anyone tell me


View Complete Post

More Related Resource Links

Controlling object serialization

I have a class called Marker and I've written SerializeToXml function that serializes the class to xml. The problem is that I'm getting xml declaration and namespace that I don't need. How can I set up the serialization so that this information is not included ? Code Snippet <?xml version="1.0" encoding="utf-16"?><Marker xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">Here is my SerializeToXml function: Code Snippet public void SerializeToXML(System.IO.StringWriter writer){            XmlSerializer mySerializer = new XmlSerializer(typeof(Marker));                     mySerializer.Serialize(writer, this);} Thanks !

WCF Serialization EDM Object


HI, I got a WCF Service with a EDM, and I got a problem with Serialization. I can't serialize this List<User> that GetAllUsers method return.

The WCF Service have a method like this:

################# Service1.svc.cs ##################
    public class Service1 : IService1
        public List<User> GetAllUsers(string term)
            using (GESEMPEntities context = new GESEMPEntities())
                var query = from user in context.User
                            where user.User_Email == term
                            select user;

                return query.ToList();

Struggling with XML De-serialization, XML Wont De-serialize into my Object


So here's the situation. I'm writing a simple program that utilizes an api from a site. All the data requested from the api returns in XML. I've had success with XML in the past so I tried giving this a shot. No such chance.


The array that's suppose to be containing at least one of the objects is null after trying to de-serialize into it, I'm sure I'm just doing something wrong. Anyway, here's the the XML, de-serializing method, and the object class.


The method:

private repositories FromXml(string xmlString)
      var xmlSerializer = new XmlSerializer(typeof(repositories));
      repositories data = (repositories)xmlSerializer.Deserialize(new StringReader(xmlString));
      return data;

The object classes:

public class repository
    public string name;

Serialization using SQL server or storing a table object as text in a text column



I have a requirement in SQL server 2008 as follows:

I need to Insert into a particular table say Output at runtime where one of the columns (Content) of type text should contain an object of another table (Audit). This is currently being done through C# by serializing the Audit table and updating the Content with the serialized value. But this needs to be done in SQL now as per the requirement.

Can this be done by creating an object of Audit and storing in Output.Content in SQL itself?

Thanks in advance for the help.





How to omit null properties in object serialization



I have a problem in object serialization , that i want to omit the null property in object to xml serialization . i.e.

My class is as
public class MainRoot

property string Element1

property List<element2> element2


public class element2
property sub1
property sub2

I want to not show the <sub2/> whereas it looks like;

Object serialization to XML string


Hi there,

Does anybody know how can I serialize an object to string that is XML representation of object.

So far I serialize object to XML file, get its content and store them in DB. I want to bypass XML file and get serialized object to string directly.


Thinking about new C# method prototypes: object as dictionary

I recently had to write a small Flickr API. I know many .Net API for Flickr already exist but I needed one for a Silverlight application. Whatever, it's only about building some querystrings so I did it by myself. It's been an opportunity to think again about a classical question: how to pass parameters to a method ?

Imagine you have a generic method to call some Flickr functions.

C# Object Oriented Programming

So far in C# Essentials we have looked at the basics of programming in C# such as variable types and flow control. Although it would be possible to write a functional program using these techniques, there is much more to becoming a proficient C# programmer. C# is, above all, an object oriented programming language and as such any C# programmer will be expected to create object-oriented applications using this language.

Object Oriented Programming

Four core concept of OOP Object Oriented Programming. 1.Inheritance, 2.Polymorphism, 3.Abstraction and 4.Encapsulation

Object-Oriented Programming Concepts

This is the first in a series of articles describing the use of object-oriented programming techniques as implemented by the C# programming language. This series follows the C# Fundamentals tutorial that beginners are advised to read first.

Overview of SharePoint Object Model

SharePoint offers a set of structured server-side objects those are widely used to program SharePoint Applications. These objects are hierarchically arranged and you can drill down through the object hierarchy to obtain the object that contains the components of SharePoint Application you need to use in your code.

What is the difference between "dynamic" and "object" keywords?

Let's take a quick look at the object keyword first. I'm not going to talk a lot about it because it's been around since C# 1.0. This keyword is nothing more than a shortcut for System.Object, which is the root type in the C# class hierarchy. (However, as Eric Lippert pointed out in his blog post, not everything in C# derives from object.) This is a powerful mechanism, since you can assign almost any value to instances of this type.

How to bind GridView and DropDownList controls using DataTable object

In .net framework 2.0, you can load a DataTable in memory by consuming a data source using a DataReader. In this version you will find the flexibility in accessing the DataReader means write access code once and use again and again using DataReader. To see the functionality of DataTable consider an example that is created using VS2005.

Jscript error: Object does not support property or method


 Hi, i have little knowledge on javascript but i need to use this code get from somewhere for a jquery to work.

I face this "Jscript runtime error: Object does not support property or method" whenever im trying to run this page.

In my experience, im get this error msg 9 out of 10 times i use javascript in my system.

Im using Microsoft Visual web developer 2008, i wonder if this is related to my problem, i not sure there is anything i need to add as reference or update anything.

But anyway, in short, i just couldn't use javascript code when using this development tool because of this sort of error.

Anyway, it happen that last time i tried use the same type of jquery code in another project and it seems to work well without an error.

But now when im try to use it again in this recent project i created, it come out with this error and i have no idea how to solve it even look through google and this forum.

It doesn't really seems like its the code problem itself although im not sure, because any javascript code just couldn't work.

So below is my code that i need to use.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></script>
<script type="text/javascript" src=&quo

Pass ASP.NET membership identity object across domain?


I am trying to figure a way to SSO with ASP.NET membership and role model.

I can implement custom membership provider which consume web services hosting on a server.

With encryption of data. No problem.

But my question is, If I sign on a website with my provider, got my identity object on that application,

could I pass it to another website on another domain which use the same provider and by doing so, do not need to login again?

If this is possible, I am going to implement this solution. Please tell me what's your take on this.

Send object from one page to another



I want to create object in 1.aspx, and then send it to 2.aspx. This methods are bad, because:

1)Send object with url, like this:


This is not confidential.


Session["field1"] = "12345"; // set
Object foo = Session["field1"]; // get

This is bad too, because in 2.aspx this fields send to textboxes, and if user go to 2.aspx without 1.aspx, he'll see old data. 

command object error


Could someone please tell me what is wrong with my syntax here?  I'd be much appreciative.


objCmd = New SQLCommand("SELECT CASE WHEN objDR('Item') = 'Enter Bill of Lading' then enterbol " _  

& "WHEN objDR('Item') = 'Bill of Lading History' THEN bolhistory " _  

& "WHEN objDR('Item') = 'Request Transfer' or objDR('Item') = 'View Transfer in Progress' THEN transfers " _  

& "END  from plantGroups where plantgroupid=@plantgroupid", objConn)

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend