CodeKeep C# Feed Aprile 30th, 2008
Description: Source: http://blogs.msdn.com/tims/archive/2004/04/02/106310.aspx
Link: http://www.codekeep.net/snippets/c76f9433-c53c-4cae-bf5e-e309b1f51207.aspx
enum Colour
{
Red,
Green,
Blue
}
// ...
Colour c = (Colour) Enum.Parse(typeof(Colour), "Red", true);
Console.WriteLine("Colour Value: {0}", c.ToString());
// Picking an invalid colour throws an ArgumentException. To
// avoid this, call Enum.IsDefined() first, as follows:
string nonColour = "Polkadot";
if (Enum.IsDefined(typeof(Colour), nonColour))
c = (Colour) Enum.Parse(typeof(Colour), nonColour, true);
else
MessageBox.Show("Uh oh!");

CodeKeep C# Feed Aprile 30th, 2008
->
CodeKeep C# Feed Aprile 30th, 2008
CodeKeep C# Feed Aprile 30th, 2008
Description: This method check a file name character
Link: http://www.codekeep.net/snippets/b0da90e1-1e30-42c5-91a6-8009b6d8fc29.aspx
public bool isSpecialCharacterExist(string strText, string strSpecialCharacters)
{
try
{
string strPattern = "[^a-zA-Z" + strSpecialCharacters + "]";
Regex objRegex = new Regex(strPattern);
bool result = objRegex.IsMatch(strText);
return result;
}
catch
{
return true;
}
}

CodeKeep C# Feed Aprile 30th, 2008
Description: Download a CSV file from an ASP.Net page. Just call the method from any button click.
Link: http://www.codekeep.net/snippets/aa3d04d0-ec11-47bd-86e6-00373e57fcf2.aspx
private void downloadCSV(DataSet ds, string filename)
{
Response.Clear();
Response.ContentType = "text/plain";
Response.AppendHeader("content-disposition",
"attachment; filename=" + filename + ".csv");
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
DataTable table = ds.Tables[0];
//Write the column headers
bool first = true;
foreach (DataColumn column in table.Columns)
{
if (!first)
{
Response.Write(",");
}
Response.Write("\"");
Response.Write(column.ColumnName);
Response.Write("\"");
first = false;
}
//Write the data
foreach (DataRow row in table.Rows)
{
Response.Write(Environment.NewLine);
first = true;
foreach (DataColumn column in table.Columns)
{
if (!first)
{
Response.Write(",");
}
Response.Write("\"");
Response.Write(row[column.ColumnName]);
Response.Write("\"");
first = false;
}
Response.Write(Environment.NewLine);
}
Response.Flush();
Response.End();
}
