|
Thanks ashu.... it is working fine
|
|
|
|
|
Hi am writing a application that have to save rectangle as an xml file.can anyone please help me to save rectangle as xml file using savedialog and xmltextwritter. my code is like this.
Stream myStream;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = saveFileDialog1.OpenFile()) != null)
{
XmlSerializer mySerializer = new XmlSerializer(typeof(DocManager));
//StreamWriter wText = new StreamWriter(myStream,Encoding.UTF8);
XmlTextWriter myWriter = new XmlTextWriter(myStream, Encoding.UTF8);
mySerializer.Serialize(myWriter,type);
// myStream.Close();
// myWriter.Close();
//wText.Write(" your xml");
//myStream.Write("your xml");
myStream.Close();
myWriter.Close();
//wText.Close()
Mamphekgo
|
|
|
|
|
Try this...
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK) {
XmlTextWriter w = new XmlTextWriter(saveFileDialog1.FileName, Encoding.UTF8);
w.WriteStartDocument(true);
w.WriteEndDocument();
w.Flush();
w.Close();
}
|
|
|
|
|
Hi
I have one comment, unrelated to the original topic:
like so many people on this web site, you do Flush followed by Close
IMO there is no need for that, every Close has an implicit Flush in it.
The only time you must call Flush (and the reason for its existence) is when you dont Close
right now, but want to make sure the data gets pushed forwards (at least one level).
This may be useful if e.g. you are logging to a file, while another app is trying to show
the latest content of same file.
|
|
|
|
|
Luc Pattyn wrote: IMO there is no need for that, every Close has an implicit Flush in it.
Yes. I think the only time that Flush should be used is if you need to flush out the buffer and keep the file open. Like how you mentioned with the log file...
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Hi,
This is related to the formatting, not the topic, of your message.
I am preparing an article on copying code snippets from a CodeProject message board to
Visual Studio; seems there are no problems when the browser used is FireFox, Safari, ...
but often problems arise when using Internet Explorer.
One of the factors is the tags that are present inside the < PRE> </PRE> block.
In your message the lines are separated by <br> tags; most other messages have
just regular newlines.
Could you please tell me how you get that, i.e. what tools you use, and how you go
about it. Thanks in advance.
|
|
|
|
|
I'm not sure I understand what you mean. I don't do anything different, and I don't see a difference from other post. Can you explain further?
|
|
|
|
|
It is about copying code snippets FROM CodeProject messages TO Visual Studio.
Seems like most browsers have no trouble, Internet Explorer does.
So if you are not using IE6/IE7 you would not be aware of this.
IE6/IE7 often looses formatting, that is when copied the data on the clipboard, it
does not always represent line breaks and indentation well, pasting it in a
Visual Studio source window drops the newlines, and/or the indentation (space/tabs),
resulting in a complete mess.
It depends on exactly how the HTML code was built in the first place, hence
on the browser the poster is using and the tags he is adding.
Hence my questions: what tools do you use, and how do you go about it
(e.g. which tags do you use normally).
TIA
|
|
|
|
|
Personally, I just type of paste code into a <pre /> tag. I assume code project automatically converts all line breaks into <br> tags.
|
|
|
|
|
|
How to iterate along each and every item of a List<t>?
|
|
|
|
|
foreach (SomeType theItem in someList) {
DoSomethingWith(theItem);
}
---
single minded; short sighted; long gone;
|
|
|
|
|
----
List<int> intList = new List<int>();
//fill the list
//...
foreach(int myInt in intList){
Console.WriteLine(myInt);
}
----
This enumerates over all integers in intList, storing them in the variable myInt inside the loop so that you can access it.
Note that you can't edit the list itself during this loop, so if you are trying to remove an element from the list you will get an exception thrown. The way around this is to make a separate list to store the elements that you want removed, then loop through those later and remove them from your original list OR, see below (looping backwards and removing elements)
----
//loops through intList and removes every 0 from the list
cont int BADVAL = 0;
for(int i = intList.Count - 1; i >= 0; --i){
if(intList[i] == BADVAL){
intList.RemoveAt(i); //removes the current index from the list
}
}
----
|
|
|
|
|
Hi PhilDanger,
Thanks for reply...
I have a specific problem.... I hope u will help me out
SeatEntity is a class having fields seat_id and row_id and properties SeatId and RowId. I stored the SeatId and RowId in a List<seatentity> now while iterating each and every cell of a dataGridView Control I want to iterate through each item in List<eeatentity> and comapre its values with the cells RowIndex and ColumnIndex....
Ur help will be much aapreciated
|
|
|
|
|
In your loop that iterates through the DataGridView, assume that you have two values RowIndex and ColumnIndex that point to the appropriate cell.
SeatEntity gridSeat = (SeatEntity)gridView[ColumnIndex, RowIndex].Value;
foreach(SeatEntity seat in seatList){
if(seat.SeatId == gridSeat.SeatId){
}
}
|
|
|
|
|
Hi I am sending u the code if u can help better
SeatChartService scs = new SeatChartService();
private void Form1_Load(object sender, EventArgs e)
{
List<seatentitiy> seat = scs.GetSeats();
//dataGridView1.DataSource = seat;
dataGridView1.ColumnCount = scs.GetColumnCount();
dataGridView1.RowCount = scs.GetRowCount();
int i = 0;
int j = 0;
foreach (DataGridViewTextBoxColumn c in dataGridView1.Columns)
{
c.HeaderText = i.ToString();
i++;
}
foreach (DataGridViewRow r in dataGridView1.Rows)
{
r.HeaderCell.Value = j.ToString();
j++;
}
SeatEntitiy seobj= new SeatEntitiy();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
foreach (SeatEntitiy se in seat)
{
//SeatEntity gridSeat = (SeatEntity)cell[ColumnIndex, RowIndex].Value;
seobj.SeatId = se.SeatId.ToString();
seobj.RowId = se.RowId.ToString();
if (cell.ColumnIndex.ToString() == seobj.SeatId.Substring(14) && cell.RowIndex.ToString() == seobj.RowId.Substring(12))
{
cell.Style.BackColor = Color.Green;
//MessageBox.Show(cell.ColumnIndex.ToString(),cell.RowIndex.ToString());
}
else
{
cell.Style.BackColor = Color.Red;
}
}
}
}
}
|
|
|
|
|
What's the problem with this code?
|
|
|
|
|
Wrong forum, see Mobile Development[^]
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
Hi,
I would like to make an application that generates unique numbers (numerics only) in sequential order (better if this way but not compulsory).
It should be able to recover in case of a crash. i.e. if the generation crashes or system crashes, then the next time its up, it should give unique numbers only, and not repeat any number previously given. This is of utmost importance.
And if crash recovery feature doesn't involve I/O, it would be better. (e.g saving numbers to disk and stuff).
Note: Random is not mandatory, unique is.
If you have a solution to this, please help.
Thank you.
|
|
|
|
|
Use GUIDs and convert them to numeric - it is a sequence of HEX anyway so it can be converted quite easily.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
Hi Colin,
this is puzzling me: I expect GUID are unique all over the universe.
They also need many bits; how can it be if a take 1 million GUIDs and convert each of them
to int, that all ints will also be unique (inside my confined process that is),
so which transformation preserves uniqueness while compressing from many to 32 bits ??
A simple hash code wont be sufficient, its only function as I understand is putting objects
into 2^32 buckets with a "good distribution".
Can you enlighten me on this ? Thanks.
|
|
|
|
|
Guids are 128 bits. No one said anything about being constrained to 32 bits.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
Thanks Colin
I confused with the GUID strings, the ones used for registering a class (and filling the
registry).
Now 128-bit isnt very much, and MSDN on Guid.NewGuid says "There is a very low probability that the value of the new Guid is all zeroes or equal to any other Guid." which may not be good
enough for the OP, he really insisted on uniqueness...
|
|
|
|
|
Oh, the OP don't have to worry about it...
However, using GUIDs is not practical due to timing requiremts and 128-bit integers handling: he don't need such complexity.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Your solution is simply not practical.
See Luc Pattyn one [^] for a better approach (at least IMHO).
BTW you don't need to convert hexadecimal chars to obtain integers from GUIDs.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|