Archive for Maggio 12th, 2008

Enum to DropDownList

CodeKeep C# Feed Maggio 12th, 2008

Description: Read an Enum in a DropDownList with the correct value

Link: http://www.codekeep.net/snippets/de3f8eb0-9481-4f0d-8d15-e02e3156cf0d.aspx

        string[] Names;

        Names = Enum.GetNames(typeof(TypePage));

        IdTypePageDropDownList1.Items.Clear();

        for (int i = 0; i < Names.Length; i++)
        {
            IdTypePageDropDownList1.Items.Add(new ListItem(
                                                            Names[i],
                                                            ((int)Enum.Parse(typeof(TypePage), Names[i])).ToString()
                                                            )
                                             );
        }

Write string to a file.

CodeKeep C# Feed Maggio 12th, 2008

Description: Writes any string to a file using StreamWriter

Link: http://www.codekeep.net/snippets/8541cdc0-7364-4a67-87b9-5c355aeda195.aspx

string text = "Hello World"

System.IO.TextWriter tw = new System.IO.StreamWriter("c:\\output.txt");
tw.WriteLine(xmlDoc);
tw.Close();