|
Thank dabuskol for your reply.
I have already fixed this bug. The problem is the name of field must be capital
Regards,
Uyen Chi
|
|
|
|
|
This is because Reflection is used to bind to properties. A property called "name", for example, is different than a property called "Name". While possible, it is a violation of the CLI (Common Language Infrastructure).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi.
Can anyone tell me or point me to a HOWTO on making messager-like messageboxes?
A have a win app in which i would like to show some notifications to the user when something occurs, but without disturbing the user.
I want to do this the same way that messenger does it when you fx have a new mail or when some friend logged in.
How do i do this?
\Regards finger
|
|
|
|
|
|
Hi,
I'm just wondering if a class with the [Serializable] attribute could be serialized to an XML file. Whats the easiest way? Where to start reading?
Thanks in advance,
Matthias
If eell I ,nust draw to your atenttion to het fakt that I can splel perfrectly well - i;ts my typeying that sukcs.
(Lounge/David Wulff)
www.emvoid.de
|
|
|
|
|
using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Collections;
using System.Data ;
/* The XmlRootAttribute allows you to set an alternate name
(PurchaseOrder) of the XML element, the element namespace; by
default, the XmlSerializer uses the class name. The attribute
also allows you to set the XML namespace for the element. Lastly,
the attribute sets the IsNullable property, which specifies whether
the xsi:null attribute appears if the class instance is set to
a null reference. */
[XmlRootAttribute("PurchaseOrder", Namespace="http://www.cpandl.com",
IsNullable = false)]
public class PurchaseOrder
{
public Address ShipTo;
public string OrderDate;
/* The XmlArrayAttribute changes the XML element name
from the default of "OrderedItems" to "Items". */
[XmlArrayAttribute("Items")]
public OrderedItem[] OrderedItems;
public decimal SubTotal;
public decimal ShipCost;
public decimal TotalCost;
}
public class Address
{
/* The XmlAttribute instructs the XmlSerializer to serialize the Name
field as an XML attribute instead of an XML element (the default
behavior). */
[XmlAttribute]
public string Name;
public string Line1;
/* Setting the IsNullable property to false instructs the
XmlSerializer that the XML attribute will not appear if
the City field is set to a null reference. */
[XmlElementAttribute(IsNullable = false)]
public string City;
public string State;
public string Zip;
}
public class OrderedItem
{
public string ItemName;
public string Description;
public decimal UnitPrice;
public int Quantity;
public decimal LineTotal;
/* Calculate is a custom method that calculates the price per item,
and stores the value in a field. */
public void Calculate()
{
LineTotal = UnitPrice * Quantity;
}
}
public class Test
{
public static void Main()
{
// Read and write purchase orders.
Test t = new Test();
t.CreatePO("po.xml");
t.ReadPO("po.xml");
t.CreatCol() ;
}
private void CreatCol()
{
XmlSerializer serializer =
new XmlSerializer(typeof(MyCoulumnClollectionClass));
TextWriter writer = new StreamWriter("Hadi.xml");
MyCoulumnClollectionClass d=new MyCoulumnClollectionClass() ;
SCol s1=new SCol() ;
s1.FieldName ="stud_no" ;
s1.DisplayName="stud_displayname";
d.Add(s1);
s1=new SCol() ;
s1.FieldName="FN2" ;
s1.DisplayName="DN2" ;
s1.AAAA="====" ;
d.Add(s1) ;
serializer.Serialize(writer, d);
writer.Close();
}
private void CreatePO(string filename)
{
// Create an instance of the XmlSerializer class;
// specify the type of object to serialize.
XmlSerializer serializer =
new XmlSerializer(typeof(PurchaseOrder));
TextWriter writer = new StreamWriter(filename);
PurchaseOrder po=new PurchaseOrder();
// Create an address to ship and bill to.
Address billAddress = new Address();
billAddress.Name = "Teresa Atkinson";
billAddress.Line1 = "1 Main St.";
billAddress.City = "AnyTown";
billAddress.State = "WA";
billAddress.Zip = "00000";
// Set ShipTo and BillTo to the same addressee.
po.ShipTo = billAddress;
po.OrderDate = System.DateTime.Now.ToLongDateString();
// Create an OrderedItem object.
OrderedItem i1 = new OrderedItem();
i1.ItemName = "Widget S";
i1.Description = "Small widget";
i1.UnitPrice = (decimal) 5.23;
i1.Quantity = 3;
i1.Calculate();
// Insert the item into the array.
OrderedItem [] items = {i1};
po.OrderedItems = items;
// Calculate the total cost.
decimal subTotal = new decimal();
foreach(OrderedItem oi in items)
{
subTotal += oi.LineTotal;
}
po.SubTotal = subTotal;
po.ShipCost = (decimal) 12.51;
po.TotalCost = po.SubTotal + po.ShipCost;
// Serialize the purchase order, and close the TextWriter.
serializer.Serialize(writer, po);
writer.Close();
}
protected void ReadPO(string filename)
{
// Create an instance of the XmlSerializer class;
// specify the type of object to be deserialized.
XmlSerializer serializer = new XmlSerializer(typeof(PurchaseOrder));
/* If the XML document has been altered with unknown
nodes or attributes, handle them with the
UnknownNode and UnknownAttribute events.*/
serializer.UnknownNode+= new
XmlNodeEventHandler(serializer_UnknownNode);
serializer.UnknownAttribute+= new
XmlAttributeEventHandler(serializer_UnknownAttribute);
// A FileStream is needed to read the XML document.
FileStream fs = new FileStream(filename, FileMode.Open);
// Declare an object variable of the type to be deserialized.
PurchaseOrder po;
/* Use the Deserialize method to restore the object's state with
data from the XML document. */
po = (PurchaseOrder) serializer.Deserialize(fs);
// Read the order date.
Console.WriteLine ("OrderDate: " + po.OrderDate);
// Read the shipping address.
Address shipTo = po.ShipTo;
ReadAddress(shipTo, "Ship To:");
// Read the list of ordered items.
OrderedItem [] items = po.OrderedItems;
Console.WriteLine("Items to be shipped:");
foreach(OrderedItem oi in items)
{
Console.WriteLine("\t"+
oi.ItemName + "\t" +
oi.Description + "\t" +
oi.UnitPrice + "\t" +
oi.Quantity + "\t" +
oi.LineTotal);
}
// Read the subtotal, shipping cost, and total cost.
Console.WriteLine("\t\t\t\t\t Subtotal\t" + po.SubTotal);
Console.WriteLine("\t\t\t\t\t Shipping\t" + po.ShipCost);
Console.WriteLine("\t\t\t\t\t Total\t\t" + po.TotalCost);
}
protected void ReadAddress(Address a, string label)
{
// Read the fields of the Address object.
Console.WriteLine(label);
Console.WriteLine("\t"+ a.Name );
Console.WriteLine("\t" + a.Line1);
Console.WriteLine("\t" + a.City);
Console.WriteLine("\t" + a.State);
Console.WriteLine("\t" + a.Zip );
Console.WriteLine();
}
protected void serializer_UnknownNode
(object sender, XmlNodeEventArgs e)
{
Console.WriteLine("Unknown Node:" + e.Name + "\t" + e.Text);
}
protected void serializer_UnknownAttribute
(object sender, XmlAttributeEventArgs e)
{
System.Xml.XmlAttribute attr = e.Attr;
Console.WriteLine("Unknown attribute " +
attr.Name + "='" + attr.Value + "'");
}
}
public class SCol
{
// public string FiledName
// {
// get
// {
// return m_fieldName ;
// }
// }
// public void SetFiledName(string f)
// {
// m_fieldName=f ;
// }
[XmlElement(ElementName = "TaxRate")]
public string FieldName
{
get
{
return m_ ;
}
set
{
m_=value ;
}
}
public string DisplayName ;
[XmlIgnoreAttribute]
public DataTable m_columnTable ;
private string m_ ;
[XmlElement]
public string AAAA ;
}
public class MyCoulumnClollectionClass : CollectionBase
{
//[XmlElement(ElementName = "Collection")]
//[XmlArrayAttribute("Items")]
public SCol this[ int index ]
{
get
{
return( (SCol) List[index] );
}
set
{
List[index] = value;
}
}
public int Add( SCol value )
{
return( List.Add( value ) );
}
public int IndexOf( SCol value )
{
return( List.IndexOf( value ) );
}
public void Insert( int index, SCol value )
{
List.Insert( index, value );
}
public void Remove( SCol value )
{
List.Remove( value );
}
public bool Contains( SCol value )
{
// If value is not of type Int16, this will return false.
return( List.Contains( value ) );
}
}
|
|
|
|
|
The SerializableAttribute has nothing to do with XML Serialization (only Runtime Serialization).
Any class can be serialized using XML Serializer (see the documentation for the XmlSerializer class in the .NET Framework SDK). Only public properties and fields are serialized, however. You can use the XML Serialization attributes (read about the classes in the System.Xml.Serialization namespace), such as the element or attribute name for a property, the data type (if you want to override the default behavior), the namespace of a class or element, etc.
Read the class documentation for the XmlSerializer in the .NET Framework SDK. There are links to a lot of topics in the .NET Framework SDK as well as several good examples and snippets of code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi..
I have a tabcontrol on a Form..On this i am adding few tabpages..On the first tabpage I used few labels and edit boxes..in the last i used a texbox control..After displaying this tabpage i am able to see all controls properly but in case of listbox control the vertical bar down arrow is missing..
can anyone help me in this..
Thanks
Sudhakar
|
|
|
|
|
Hi
Can you send a from to check the problem, please
|
|
|
|
|
Unless ScrollAlwaysVisible is set to true , your scroll bar will not appear unless more items than the ListBox can display at a time are present.
If this is not the problem, please be a little more descriptive, such as posting a snippet of relevant code (please do not post the whole thing), describing what you're doing with the ListBox , etc. We can't see your code nor do we know it. Unless you're specific about a problem, we really can't help you.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
That was not my problem..I am able to see the vertical scroll bar correctly but the down arrow in that scroll bar is missing..I want to put a snapshot of it as an attachement..But i am not able to find how i can do tht in this forum..can u plz tell me so that i can send a snapshot..
Thanks
Sudhakar
|
|
|
|
|
Most likely your control is being clipped. Make sure that the entire ListBox control is within the client region of the TabPage . If you can resize the TabControl , make sure you set the Anchor or Dock properties for your ListBox accordingly.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Use Alt-Print Scrn.
Then go to MSPaint.
Press Ctrl-V.
Save as desired image format and post it!.
Yes, I program in VB, but only to feed my addiction to a warm place to sleep and food to eat!
Visit my Code Project blog (Mobile Audio project)[^]
|
|
|
|
|
I know all the above steps..But i want to know how to attach the saved image while postiing in this forum.. I didnt see any option while posting this message which says "attach ur files" .. I tried copying the image and paste it inline but tht is also not working..
Thanks
Sudhakar
|
|
|
|
|
I have a custom class called Invoice, which has a property Customer. This property Contains a reference to a customer class.
I want to bind a combobox to a the list of customers and bind the selected value to my Customer property. How can I do this?
"Every rule in a world of bits and bytes can be bend or eventually be broken"
|
|
|
|
|
Bind the ComboBox to your Customers property, and set the DisplayMember and ValueMember to the properties for a Customer class that you want to bind:
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "ID";
comboBox1.DataSource = someObject.Customers; See the property documentation for the ListControl.DataSource property for more information and an example (ComboBox extends ListControl ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi All
I am calling the function from DLL using InteropServices. But when i called the function that accept the string as parameter NullReference exception is thrown.
Actual function signature:
int GetName(int pModel, int iVar, char *pszVarname);
Function Signature for C#:
[DllImport("C:\\MyFunctions.dll")]
public static extern int GetName(int nProb, int nIndex, ref string sVarName);
Fuction Call:
string sVarName;
int nErrCode, i;
i = 14;
sVarName = "x123456";
nErrCode = GetName(nProb,i, ref sVarName); //Getting NullReferenceException
Thanks in advance
qur
|
|
|
|
|
Don't ref the string. A char* is a string . The signature in C# should be (and loose the path - put the DLL in a directory in your PATH environment variable, or the current application directory):
[DllImport("MyFunctions.dll", CharSet=CharSet.Ansi)]
public static extern int GetName(int nProb, int nIndex, string sVarName); Also notice the CharSet field in the DllImportAttribute . .NET deals with Unicode strings. If you don't specify a CharSet , CharSet.Ansi is used by default for C# and VB.NET, but it's still a good idea to specify it for readability.
Also notice there's no out or ref keyword for the sVarName parameter (which, by the way, can be called anything you want). A String (C# alias string ) is already a reference type.
Also, if you want your code to be portable, those int parameters and return should actually be IntPtr . An int in C/C++ is a processor-dependent bit width (i.e., 32 bits on a 32-bit CPU, 64 bits on a 64-bit CPU). int in .NET (an Int32 , actually) is always 32 bits. When .NET 2.0 is released and if your code runs on a 64-bit platform (and your native DLL is recompiled for a 64-bit platform), your call will fail.
Finally, never make P/Invoke'd methods public (unless the class that declares them is private or internal). Native function calls are unmanaged, so the CLR can't determine if someone would exploit your code. Depending on your native implementation, someone could easily perform a buffer overrun using the string variable and the CLR couldn't prevent it because it's unmanaged. P/Invoke'd methods are typically wrapped in a class that encapsulates the functionality that you're trying to use in a native DLL. Many classes throughout the .NET Framework Class Library (FCL) - such as every Control in Windows Forms - does this.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi all...
i am hoping this is a simple request, but, i have developed a Java web service running under LINUX, and from what i can see, the service is coming up quite nicely... but...
i am using a C# app to call the web service, and i keep on getting a java.rmi.RemoteException coming up during debug, but no info on what that exception has in it...
is there any way of getting the exception message so i can handle it?
cheers and thanks in advance...
nik
Nik Vogiatzis
PhD Candidate: University of South Australia
+++++++++++++++++++++++++++
Developing new generation Traffic Micro-simulation Tools for Traffic Engineers
|
|
|
|
|
Where is the exception occuring? On the client or server? Unless the generated web service proxy also contains a definition of the java.rmi.RemoteException , this information wouldn't be available to the client because that exception doesn't exist in the .NET FCL. The exception on the client should've been wrapped in a generic Exception (typically). Depending on mappings, the Message property may or may not have a message associated with it (other than any generic, default message that might be configured).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi heath...
thanks for the quick response...
long story short, the error is occuring at the server end (on a LINUX server running AXIS)...
i would suggest that the web service proxy doesn't have the definition as the Java2WSDL and WSDL2Java are, from my understanding, not designed with .NET clients in mind...
i am wondering 'how' i am meant to go about wrapping the exception, or if there is a better way you could suggest...
thanks again, i appreciate the help...
cheers
nik
Nik Vogiatzis
PhD Candidate: University of South Australia
+++++++++++++++++++++++++++
Developing new generation Traffic Micro-simulation Tools for Traffic Engineers
|
|
|
|
|
You don't wrap it. If an exception occurs, the client should see it, even if it's a generic error wrapped in an Exception class.
If you're getting an exception on the server, you'll simply need to debug what's going on.
There are problems when mixing Java and .NET for web services, typically when you use types that either aren't correctly defined in the WSDL. The class generator (same as wsdl.exe on the command-line) might not be generating the right classes.
Without specifics, it's hard to say.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hmm... no probs...
please tell what specifics you need that will help you help me...
as for the class itself, the interface is from memory (as the code is at work)...
<br />
public interface SysReport extends (...)<br />
{<br />
java.lang.String[] runReport(java.lang.String var1,..., java.lang.String[] err);<br />
}<br />
there are whole lot of variables in the middle, which i just can't remember right now, but i will send them once i get to work...
cheers and thanks for your help so far...
nik
Nik Vogiatzis
PhD Candidate: University of South Australia
+++++++++++++++++++++++++++
Developing new generation Traffic Micro-simulation Tools for Traffic Engineers
|
|
|
|
|
Hi,
I was wondering if anyone has seen an example of how one can send an HTTPWebRequest, passing in a schema to define what information your sending and have an app, aspx? file retrieve process the request and send a response
Kind Regards,
Rik
|
|
|
|
|
You just need to upload the file via POST. If you look at the HttpWebRequest.GetRequestStream method documentation in the .NET Framework SDK, you'll find a nice example.
Note that this uses POST, though, not GET (which uses the query string). Sending a schema via GET is riddled with problems, one of which is size restrictions. A GET query string can only be so long (128 bytes, IIRC), and schemas can easily break that barrier.
In ASP.NET, there is an easy way to get files that are uploaded. See the HttpRequest.Files property documentation in the SDK. Use Page.Request to get the HttpRequest , then enumerate the Files property. Do what you need with the schema then send your response using the Page.Response property (an HttpResponse ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|