Click here to Skip to main content
15,903,854 members
Home / Discussions / C#
   

C#

 
QuestionRe: Extract Image from Excel Files Pin
Member 425417926-Feb-08 5:02
Member 425417926-Feb-08 5:02 
GeneralOutlook plugin programmer needed Pin
Spinnerdog26-Feb-08 2:18
Spinnerdog26-Feb-08 2:18 
Generaltreeview afterselect problem Pin
Rick van Woudenberg26-Feb-08 1:42
Rick van Woudenberg26-Feb-08 1:42 
GeneralRe: treeview afterselect problem Pin
Bekjong26-Feb-08 2:11
Bekjong26-Feb-08 2:11 
GeneralRe: treeview afterselect problem Pin
John_Adams26-Feb-08 3:03
John_Adams26-Feb-08 3:03 
GeneralRe: treeview afterselect problem Pin
Bekjong26-Feb-08 3:19
Bekjong26-Feb-08 3:19 
GeneralRe: treeview afterselect problem Pin
Xmen Real 26-Feb-08 4:22
professional Xmen Real 26-Feb-08 4:22 
QuestionXml Serialization - deserialize a List problem Pin
Nathan Gloyn26-Feb-08 1:32
Nathan Gloyn26-Feb-08 1:32 
Does anybody know a way that I can perform the deserialization of the xml into a List<T> that doesn't require me to create a class that inherits List<> and overrides the serialization?

My current predicament is that I have the following Xml doc:

<Outstanding>
<WorkItem UserId="2014C908-1FD3-447C-B6EA-56DDB1602E45">
<TotalItems>74</TotalItems>

<Tables>
<Table Id="0">
<Name>Table0</Name>

<ItemCount>74</ItemCount>
</Table>
</Tables>
</WorkItem>

<WorkItem UserId="E40B31E5-E342-424C-A12B-8EF2D819DB3E">
<TotalItems>41</TotalItems>

<Tables>
<Table Id="0">
<Name>Table0</Name>

<ItemCount>41</ItemCount>
</Table>
</Tables>
</WorkItem>
</Outstanding>


And I have the following class:

public class WorkItem
{
#region Member variables

private int _totalItems;
private List<WorkItemTable> _tables;
private Guid _userId;
private MembershipUser _user;

#endregion

public MembershipUser User
{
get { return _user; }
}

public int TotalItems
{
get { return _totalItems; }
}

public List<WorkItemTable> Tables
{
get { return _tables; }
}


}


As you can see the class doesn't match the Xml doc especially the User property, ideally I want to get the userId from the Xml doc and then query the Membership provider to return me the actual MembershipUser object.

I have tried using IXmlSerializable, the ReadXml specifically is:

public void ReadXml(System.Xml.XmlReader reader)
{
reader.MoveToElement();

reader.MoveToFirstAttribute();

_userId = new Guid(reader.Value);

reader.ReadToFollowing("TotalItems");
// Try and get the total items
if (!int.TryParse(reader.ReadElementString("TotalItems"), out _totalItems))
throw new SerializationException("Unable to de-serialize WorkItem due to problem with TotalItems element");

// Now we have read the specific items for the WorkItem de-serialize the tables
XmlSerializer serializer = new XmlSerializer(typeof(List<WorkItemTable> ), new XmlRootAttribute("Tables"));
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");

_tables = (List<WorkItemTable> )serializer.Deserialize(reader);

}


Which works fine for a single WorkItem element but when I attempt to execute:


XmlSerializer s = new XmlSerializer(List<WorkItem> );

TextReader reader = new StringReader(xmlData);

s.Deserialize(reader);


The XmlSerializer passes a reader that iterates over all of the WorkItem elements which means I end up with only a single item in the list rather than multiple items entered in the Xml.
AnswerRe: Xml Serialization - deserialize a List problem Pin
Raji Vulava6-Jan-10 20:11
Raji Vulava6-Jan-10 20:11 
QuestionCompile Visual J# code through C# code [modified] Pin
i_want_to_learn_c#26-Feb-08 0:52
i_want_to_learn_c#26-Feb-08 0:52 
GeneralRe: Compile Visual J# code through C# code Pin
leppie6-Mar-08 3:32
leppie6-Mar-08 3:32 
GeneralRe: Compile Visual J# code through C# code Pin
leppie6-Mar-08 3:32
leppie6-Mar-08 3:32 
Generalloader lock error [modified] Pin
rao raja26-Feb-08 0:45
rao raja26-Feb-08 0:45 
GeneralRe: loader lock error Pin
leppie6-Mar-08 2:33
leppie6-Mar-08 2:33 
Generalproblem with windows service Pin
Prabhat00326-Feb-08 0:45
Prabhat00326-Feb-08 0:45 
GeneralRe: problem with windows service Pin
Vikram A Punathambekar26-Feb-08 1:27
Vikram A Punathambekar26-Feb-08 1:27 
GeneralRe: problem with windows service Pin
Prabhat00326-Feb-08 1:34
Prabhat00326-Feb-08 1:34 
GeneralRe: problem with windows service Pin
Pete O'Hanlon26-Feb-08 9:56
mvePete O'Hanlon26-Feb-08 9:56 
GeneralRe: problem with windows service Pin
Prabhat00326-Feb-08 18:51
Prabhat00326-Feb-08 18:51 
GeneralIssue regarding Serialization [modified] Pin
free_soul42426-Feb-08 0:38
free_soul42426-Feb-08 0:38 
GeneralRe: Issue regarding Serialization Pin
Le centriste26-Feb-08 4:58
Le centriste26-Feb-08 4:58 
QuestionWriting an Image in Excel Cell Comment using C# Pin
Neeraj Kr26-Feb-08 0:28
Neeraj Kr26-Feb-08 0:28 
QuestionExecuting an EXE Pin
M. J. Jaya Chitra26-Feb-08 0:26
M. J. Jaya Chitra26-Feb-08 0:26 
GeneralRe: Executing an EXE Pin
Luc Pattyn26-Feb-08 0:29
sitebuilderLuc Pattyn26-Feb-08 0:29 
QuestionDraw Text in C# using OpenGL Pin
Yasir Nawazish Ali26-Feb-08 0:18
Yasir Nawazish Ali26-Feb-08 0:18 

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.