--The following exemplifies writing to a text file in a scenario where
--permissions need to be temporarily altered:
string tempPath = @"c:/file.txt";
if (File.Exists(tempPath))
{
FileIOPermission fio =
new FileIOPermission(FileIOPermissionAccess.Write, tempPath);
fio.AddPathList(FileIOPermissionAccess.Write |
FileIOPermissionAccess.Read, tempPath);
fio.Demand(); --use the .Demand method to obtain permission
StreamReader reader = new StreamReader(tempPath);
string content = reader.ReadToEnd();
reader.Close();
for (int j = 0; j < stringToReplace.Length; j++)
{
content = Regex.Replace(content, stringToReplace[j],
replacementString, RegexOptions.IgnoreCase);
}
StreamWriter writer = new StreamWriter(tempPath);
writer.Write(content); writer.Close();
}
Chief Practicing His Modeling Skills
Deprecated ‘center’ Tag In HTML 5
Ok, so if your web site is no longer centered in FireFox but still works in Internet Explorer, then remember back to when the ‘center’ tag was deprecated back in HTML 5. FireFox simply will not tolerate this tag any longer and pushes to the standard of having tags DESCRIBE its contents and not DEFINE them.
Anyway, you might get away with replacing your ‘center’ tags with:
‘div style=”text-align: center;”‘
However, it would probably be better to change your architecture to reference an “auto” property in your .css :
“margin: auto;”
“margin-left: auto;”
“margin-right: auto;”
Rapid Application Development (RAD) With The DataGridVIew
Earlier this week, I came across a new developer who was trying to loop through his DataGridView to get the data out of it. Usually, RAD development with the DataGridView just does not work for most of my business scenarios but here was a clear case where it worked well so I will paste my instructions here:
1. Create your form.
2. Drag a DataGridView to your form. A pop-up window entitled “DataGridView Tasks” should appear. If not, then there should be a small arrow in the top right-hand corner of the DataGrid.
3. From here, select “Choose Data Source –> Add Project Data Source.” This should trigger a wizard that will assist you in setting up your database connection. Select “Database”, then select your table, and continue to walk through the wizard.
4. If you return to your form, you should now see a DataSet, a BindingSource, and a TableAdapter. These are the tools that you will use to get and save your DataGrid data.
5. Note that in your Form_Load event, there should be a like of code similar to the following:
this.tableAdapter.Fill(this.dataSet1.table);
6. Now, add a button to your form and create a _Click event. Here you should be able to save your data by entering your version of the following lines of code:
this.Validate();
this.tableBindingSource.EndEdit();
this.tableAdapter.Update(dataSet1.table);
7. The data should now be updated in your DataGrid and database.
This code will fill your DataGridView upon load. You can modify the SQL in the DataSet to pull only select data if you wish.
http://msdn.microsoft.com/en-us/library/ms171933(v=vs.80).aspx
SQL: Setting DateTime Value to Zero
–using DATEDIFF can set the time portion of your DateTime value to zeros –Handy!
DECLARE @Day DATETIME
SET @Day = DATEADD(DAY, -7, DATEDIFF(Day, 0, GETDATE()))