2009-07-07
Project Template
I spent a week doing the flex in a week and then it was time to come up with an project to see how this flex thing really works. This is where the contest I won came into play I won $100 of templates and got this template so I figured what better way to learn flex that to try and recreate it using flex instead of boring old flex so project template was born, I will update here as I work through it with all source code included.
Out in the Wild
2009-07-06
Excel Reader Writer (excel not required)
public void CorichExcel()
{
string file = "C:/excel.xls";
string sheet = "";
try
{
//Gets a liost of sheets from the excel file
string[] sheets = Corich.Excel.ReaderWriter.GetSheets(file);
sheet = sheets[0];
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
//Check to see if the sheet exist
if (Corich.Excel.ReaderWriter.SheetExists(file, sheet))
{
//gets a list of colums from the first sheet in the excel file
string[] columns = Corich.Excel.ReaderWriter.GetColumns(file, sheet);
//Loads the data in the first excel sheet into a data table
DataTable data = Corich.Excel.ReaderWriter.Read(file);
//Writes the data from the first sheet to a new excel file, currently only writes to xlsb files
Corich.Excel.ReaderWriter.Write("C:\new_file.xlsb", data);
//Writes the data from the first sheet to a new excel file in the temp directory then opens it, currently only writes to xlsb files
Corich.Excel.ReaderWriter.WriteToTemp("new_file.xlsb", data, true);
}
}
You can download the .dll and the source here the code is under the GNU GPL licence it would be nice to point people to my site if you use it.
2009-07-03
Excel Sheet Names using ODBC
string filename = "your filename";
string connectionString;
connectionString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};dbq=" + filename + ";fil=excel 12.0;readonly=0;usercommitsync=Yes";
OdbcConnection myConnection = new OdbcConnection(connectionString);
myConnection.Open();
DataTable data = myConnection.GetSchema("Tables");
myConnection.Close();
List sheets = new List();
foreach (DataRow sheet in data.Rows)
{
sheets.Add(sheet["TABLE_NAME"].ToString().Trim('\'').TrimEnd('$'));
}
P.S. I have built a whole static class library to read and write excel sheets I will post it here when I have some time to comment it.
2008-11-25
Auto Redirect to Login in page on an ASP.NET Website and keep styles
<!-- allows access Styles and Images directories-->
<location path="Styles">
<system.web>
<authorization>
<allow users="?">
</allow></authorization>
</system.web>
</location>
<location path="Images">
<system.web>
<authorization>
<allow users="?">
</allow></authorization>
</system.web>
</location>
<system.web>
...
<authentication mode="Forms">
<!-- When a user does not have access redirects to the login-->
<forms loginUrl="Login.aspx" name="Login">
</forms></authentication>
<!-- Blocked access to all undecleared directores/files-->
<authorization>
<deny users="?">
</deny></authorization>
...
</system.web>
2008-11-17
Pirates are not always cool
2008-10-31
Regualar Expression bug in C#
I am currently working on a exception reporting system for work. As part of the system I am Creating a way to automatically create a bug in our bug reporting system when someone creates an error report or increase the count when an error has occured more than once. To do this I created an regular expression that grabs the relative filename and line number, I used this code:
Regex regex = new Regex("^.*\\(?'filename'.*):line (?'line'[0-9].)");
Match match = regex.Match(stackTrace);
I tested the code and got an following error
parsing "^.*\(?'filename'.*):line (?'line'[0-9].)" - Too many )'s.
After googleing i found exactly nothing that would help and 2 hours after that I came up with a nasty hack, my thinking was the proble is to do with the "\\" so how about replacing all the "\" with an "`" and then using String.Replace to replace the string(see below) it worked.
Regex regex = new Regex("^.*@(?'filename'.*):line (?'line'[0-9].)");
Match match = regex.Match(stackTrace.Replace('\\', '@'));
Probably someting you want to fix Microsoft.