|
Hi!
I have the following classes:
<br />
[XmlRoot("shoppingList")]<br />
public class ShoppingList<br />
{<br />
private ArrayList listShopping;<br />
<br />
public ShoppingList()<br />
{<br />
listShopping = new ArrayList();<br />
}<br />
<br />
[XmlElement("item")]<br />
public Item[] Items<br />
{<br />
get<br />
{<br />
Item[] items = new Item[listShopping.Count];<br />
listShopping.CopyTo(items);<br />
return items;<br />
}<br />
set<br />
{<br />
if (value == null) return;<br />
Item[] items = (Item[])value;<br />
listShopping.Clear();<br />
foreach (Item item in items)<br />
listShopping.Add(item);<br />
}<br />
} <br />
<br />
public int AddItem(Item item)<br />
{<br />
return listShopping.Add(item);<br />
}<br />
}<br />
<br />
public class Item<br />
{<br />
[XmlElement("name")]<br />
public string name;<br />
[XmlElement("price")]<br />
public double price;<br />
<br />
public Item()<br />
{<br />
}<br />
<br />
public Item(string Name, string Price)<br />
{<br />
name = Name;<br />
price = Convert.ToDouble(Price);<br />
}<br />
}<br />
When I Serialize it I get the following XML back:
<br />
<?xml version="1.0" encoding="utf-8"?><shoppingList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><item><name>eggs</name><price>1.49</price></item><item><name>bread</name><price>0.99</price></item></shoppingList><br />
As you can see from the definition of the ShoppingList class, I have an attribute [XmlElement] defined before the Items property, with the "items" name. So in my XML every element is <item>. What can I do, so that when I serialize my ShoppingList object, each "item" element will have it's own name.
So, one element will be "Table1", next will be "Table2", and so on.
Any help greatly appreciated.
Thank you very much.
|
|
|
|
|
First of because the Items property returns an array you should use the XmlArray attribute class:
<br />
[XmlArray("Items")]<br />
public Item[] Items<br />
{<br />
}<br />
To specify a name for each item use the XmlAttribute class like this:
<br />
public class Item<br />
{<br />
[XmlAttribute("name")]<br />
public string name;<br />
....<br />
|
|
|
|
|
Hello.
I am using the Windows Encrypted File System to encrypt a file. I want to transfer this file across a network to another computer in its encrypted state so i am trying to use the OpenEncryptedFileRaw Read, Write and Close api methods. (http://msdn2.microsoft.com/en-us/library/aa365429(VS.85).aspx[^])
I've found an example that uses ReadEncryptedFileRaw to save a file in its encrypted state, which seems to work fine.(http://www.jensign.com/JavaScience/dotnet/rawefs/rawefs.cs[^])
However I am having trouble understanding the call back functions and the IntPtr's. I need to convert the raw efs file created from rawefs.cs back to the files original state using WriteEncrypedFileRaw, but all my attempts to write an import call back required by the WriteEncryptedFileRaw api have failed.
Has anyone used these api methods in C#, know of an example or just in general have any helpful advice as to how to go about writing such a call back?
Thanks.
|
|
|
|
|
When I run setup of a Windows Service installation screen. How can I catch the cancel button event for the “Set Service Login” screen?
Thanks in advance,
Ken
|
|
|
|
|
Hi,
I am trying to create a log file with the following stmt(in C#):
private LogWriter DataLog = new LogWriter(new System.IO.StreamWriter( @"C:\"+DateTime.Now.ToLocalTime()+".txt", false ));
I get the exception - "The given path's format is not supported."
when i try to access the DLL (with this stmt) in another console applic.
Can anyone suggest me what the problem could be?
Thanks,
Priya.
|
|
|
|
|
A datetime string has characters which are illegal when used in file names. For example "/" is not allowed.
You could either try using DateTime.Now.Ticks which would give you a value which contains only numeric characters. Or you could try something like this:
<br />
DateTime time = DateTime.Now;<br />
String filename = time.Year.ToString("0000") + time.Month.ToString("00") + time.Day.ToString("00") + time.Hour("00") + time.Minute("00") + time.Second("00");<br />
<br />
private LogWriter DataLog = new LogWriter(new System.IO.StreamWriter( @"C:\"+filename+".txt", false ));<br />
A third option would be to use the String.Replace method to remove spaces ' ', colons ':' and forward slashes '/' from the datetime string.
Mark's blog: developMENTALmadness.blogspot.com
Funniest variable name:
lLongDong - spotted in legacy code, was used to determine how long a beep should be. - Dave Bacher
|
|
|
|
|
Mark J. Miller wrote: String filename = time.Year.ToString("0000") + time.Month.ToString("00") + time.Day.ToString("00") + time.Hour("00") + time.Minute("00") + time.Second("00");
do you go round the block to reach you're neighbour's house?
string fileName = time.ToString("yyyyMMddhhmmss");
|
|
|
|
|
J4amieC wrote: do you go round the block to reach you're neighbour's house?
You're right, my answer was a kludge, and I don't know why I forgot about the DateTime overload. I appreciate you pointing out the right way to do it, that's why I try and post answers on these forums - to try and improve my skills by solving problems and getting feedback. I need it because I've never worked in a place where peer reviews are done and am 100% self-taught.
But there's no need to be so condesending.
Mark's blog: developMENTALmadness.blogspot.com
Funniest variable name:
lLongDong - spotted in legacy code, was used to determine how long a beep should be. - Dave Bacher
|
|
|
|
|
Mark J. Miller wrote: I need it because I've never worked in a place where peer reviews are done and am 100% self-taught.
Sounds pretty similar to me.
Mark J. Miller wrote: But there's no need to be so condesending.
Sorry, you took it like that. It was supposed to be sarcastic humour! FAIL!
|
|
|
|
|
Well, maybe I need to work on my sense of humor. When I compare my answer with what it should have been I feel pretty silly. I'll just blame it on Monday.
Mark's blog: developMENTALmadness.blogspot.com
Funniest variable name:
lLongDong - spotted in legacy code, was used to determine how long a beep should be. - Dave Bacher
|
|
|
|
|
Mark J. Miller wrote: But there's no need to be so condesending.
Maybe it'll drive the message home? I know it works for me.
|
|
|
|
|
Hi,
shivapriyak wrote: Can anyone suggest me what the problem could be?
it suffices to look at the string you are giving as a path to the StreamWriter constructor.
you could either show it (with Console.WriteLine, or MessageBox.Show; or use the debugger
to watch it).
You can create a valid string using the ToString() method of the DateTime class,
something like DateTime.Now.ToString("yyyyMMdd") would include the date info,
without any time info.
Read the doc for the details.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
modified on Monday, April 14, 2008 1:37 PM
|
|
|
|
|
Hi,
I am working with C#. In my project I need to take printout of a form in report fashon. This form comprises of pictures, texts, graphs and other controls. So I have decided to take the print out from the screenshot of the form. For doing that I have used bitblt() function first. But the printing quality with that is really very poor. So I have decided to use stretchblt() function for getting a better quality.
Now I need to take the device context of the available printer first for using the stretchblt() function successfully. But the usual getprinterdc() function (supported in MFC) is not working in C#. So plz tell me how can I solve this problem. I am using the following code:
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
public static extern int SetStretchBltMode(IntPtr hdcDest, int nStretchMode);<br />
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
public static extern int StretchBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int nWidthSrc, int nHeightSrc, System.Int32 dwRop);<br />
..<br />
..<br />
..<br />
private void CaptureScreen()<br />
{<br />
Graphics mygraphics = this.CreateGraphics();<br />
..<br />
..<br />
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = here I have to retrieve the available Printer DC as my destination DC
<br />
SetStretchBltMode(dc2, 4);
StretchBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height - 75, dc1, 0, 75, this.ClientRectangle.Width, this.ClientRectangle.Height, 13369376);
..<br />
..<br />
..<br />
memoryImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);<br />
}
Plz also let me know if u know any better solution of this problem
Thanks in advance
Faysal
|
|
|
|
|
Hi,
if you are using .NET there is no need for unmanaged code, BitBlt, Decide Contexts, ...
when printing.
Basically the code that is used to paint to the display is reused to paint to the printer.
So render your page on the display the way you want it, then use the normal printing
mechanism to get it printed.
I have a very simple example in my Sokoban article.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I need to open a new form in the same boundaries as the old one (so that it completely covers the old one), and when I move the new one, that the old ones moves also. The point is that the users can't see the old form until he finishes with the new one.
Any idea how to achieve this?
Thanks
|
|
|
|
|
Hi,
If it is the case, then why dont you hide the old form till you complete the new form operation. Once the new form operation completed, then you can make visible your new form true.
Regard
A AntonySP
Good Is Not Good When Better Is Expected.
|
|
|
|
|
Yeah, I guess I could do that, but I want the functionality similar to that when you install a new program, you have to click next->next->... and so on, and the all appear in the same boundaries...
|
|
|
|
|
Isn't there a wizard control built into Winforms ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Ok,
If the old and new form having parent and child relationship then trigger the OnMove event of current new form. Inside that write the code like
this.parent.location=this.location.
Hope this logic will help to you.
Regards
A AntonySP
Good Is Not Good When Better Is Expected.
|
|
|
|
|
Thanks to everyone who took the time to help me
I think I've finally figured it out
Thanks again
|
|
|
|
|
My prefered method is to define both forms as controls, put them on the one form, and swap between them.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Is there some tutorial on how to do that? I can't really hit the right keyword on Google...
|
|
|
|
|
It's super easy. Create controls instead of forms, make them the same size, ise the visible property to make sure one is always visible and they are never both visible at once.
But, I think for what you want to do, I'd google C# Wizard.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
Hi,
I am using DataGridView in C# for windows application. I want to align the column header as ceneter. But I am not able to find any of the property to align the header text of column. It automatically aligned left. You have any solution for this.
Regards
A AntonySP
Good Is Not Good When Better Is Expected.
|
|
|
|