Friday, October 15, 2010
Tuesday, October 12, 2010
JQuery Template Plugin
JQuery officially released new plugins. Please check here . http://blog.jquery.com/2010/10/04/new-official-jquery-plugins-provide-templating-data-linking-and-globalization/
Example.
I would describe only main steps.
Step 1. Include file
<script src="<%= Url.Content("~/Scripts/jquery.tmpl.js") %>" type="text/javascript"></script>
Step - 2. Template Structure :
<
<table width="100%">
<tr id=rec${UserName}>
<td width="20%">${FirstName}</td>
<td width="20%">${LastName}</td>
<td width="20%">${UserName}</td>
<td width="20%">${Email}</td>
<td align="center" width="5%" title="Edit"><img src="<%
<td align="center" width="5%" title="Delete"><img src="<%
</tr>
</table>script id="userTemplate" type="text/x-jquery-tmpl"> =Url.Content("~/Images/IconEditRecord.png") %>" alt="Edit" onmouseover="this.style.cursor='pointer';" onclick=showdialog('${UserName}'); /></td>=Url.Content("~/Images/IconXRed.png") %>" alt="Delete" onmouseover="this.style.cursor='pointer';" onclick="deleteUser(this,'${UserName}');" /></td></
Step 3 - Where to render
<table id="UserList">
Step 4 - Ajax Call and Append Data
Example.
I would describe only main steps.
Step 1. Include file
<script src="<%= Url.Content("~/Scripts/jquery.tmpl.js") %>" type="text/javascript"></script>
Step - 2. Template Structure :
<
<table width="100%">
<tr id=rec${UserName}>
<td width="20%">${FirstName}</td>
<td width="20%">${LastName}</td>
<td width="20%">${UserName}</td>
<td width="20%">${Email}</td>
<td align="center" width="5%" title="Edit"><img src="<%
<td align="center" width="5%" title="Delete"><img src="<%
</tr>
</table>script id="userTemplate" type="text/x-jquery-tmpl"> =Url.Content("~/Images/IconEditRecord.png") %>" alt="Edit" onmouseover="this.style.cursor='pointer';" onclick=showdialog('${UserName}'); /></td>=Url.Content("~/Images/IconXRed.png") %>" alt="Delete" onmouseover="this.style.cursor='pointer';" onclick="deleteUser(this,'${UserName}');" /></td></
Step 3 - Where to render
<table id="UserList">
Step 4 - Ajax Call and Append Data
Monday, October 11, 2010
Powershell script that uses 7-zip to compress all files in a parameterizable folder
Powershell script that uses 7-zip to compress all files in a parameterizable folder that match the file pattern provided by the user.Any file that has not been modified in more than a particular time will be compressed. The compressed archive should be verified using the command-line compression tool. Once the compressed archive is validated, then the original file should be deleted. All arguments should be passed to the script at the command-line.
(Please not that this script has not been fully tested and can really be harmful for the system, try it at your own risk :D)
Param
($SourcePath = $(Read-host "Please enter the source directory path e.g. d:\data\")),
($TargetPath = $(Read-host "Please enter the target path e.g. d:\all\archive.zip")),
($Days = $(Read-Host "Files older than days?")),
($Pattern = $(Read-Host "Enter file pattern, e.g. *.txt"))
$CurrentDate = Get-Date
$LimitDate = $CurrentDate.AddDays(-$Days)
$Files = get-childitem $SourcePath -include $Pattern -recurse | where {$_.LastWriteTime -le $LimitDate}
$FileNames = ""
foreach ($File in $Files)
{
write-host "File Name : $File " $File.LastWriteTime
$FileNames = $FileNames + " " + $File
}
write-host "Files to compress : " $FileNames
if($FileNames.Trim() -ne "")
{
powershell "&'c:\program files\7-zip\7z'" a $TargetPath $SourcePath+$Pattern
#powershell.exe "&'c:\program files\7-zip\7z'" t $TargetPath *.* -r
foreach ($File in $Files)
{
write-host "Deleting file :"$File
remove-item $File
}
}
else
{
write-host "No files to compress"
}
write-host "Operation successful!"
(Please not that this script has not been fully tested and can really be harmful for the system, try it at your own risk :D)
Param
($SourcePath = $(Read-host "Please enter the source directory path e.g. d:\data\")),
($TargetPath = $(Read-host "Please enter the target path e.g. d:\all\archive.zip")),
($Days = $(Read-Host "Files older than days?")),
($Pattern = $(Read-Host "Enter file pattern, e.g. *.txt"))
$CurrentDate = Get-Date
$LimitDate = $CurrentDate.AddDays(-$Days)
$Files = get-childitem $SourcePath -include $Pattern -recurse | where {$_.LastWriteTime -le $LimitDate}
$FileNames = ""
foreach ($File in $Files)
{
write-host "File Name : $File " $File.LastWriteTime
$FileNames = $FileNames + " " + $File
}
write-host "Files to compress : " $FileNames
if($FileNames.Trim() -ne "")
{
powershell "&'c:\program files\7-zip\7z'" a $TargetPath $SourcePath+$Pattern
#powershell.exe "&'c:\program files\7-zip\7z'" t $TargetPath *.* -r
foreach ($File in $Files)
{
write-host "Deleting file :"$File
remove-item $File
}
}
else
{
write-host "No files to compress"
}
write-host "Operation successful!"
Test 7zip archive
7z t archive.zip *.doc -r Test the integrity of .doc files in the archive. where -r is recursive (subdirectories) switch.
7z t archive.zip *.* -r
Test the integrity of all files.
Friday, October 8, 2010
Powershell script to compress files
I have used 7zip as a command line compression tool. http://www.7-zip.org/
Following script compresses all files that match specific file pattern e.g. *.txt, *.doc, *.png etc.
It should also work with Universal Naming Convention(UNC) Paths. e.g.
file://10.10.10.63/SharedDocs/archive.zip etc.
$Path = $(Read-Host "Enter Path and file pattern e.g. c:\zip\*.txt")
$Files = get-childitem $Path -include $Pattern -recurse
$FileNames = ""
foreach ($File in $Files)
{
write-host "File Name : $File " $File.LastWriteTime
$FileNames = $FileNames + " " + $File
}
write-host "Files to compress : " $FileNames
if($FileNames.Trim() -ne "")
{
powershell.exe -noexit "&'c:\program files\7-zip\7z'" a c:\target\archive.zip $FileNames
}
else
{
write-host "No files to compress :D"
}
Following script compresses all files that match specific file pattern e.g. *.txt, *.doc, *.png etc.
It should also work with Universal Naming Convention(UNC) Paths. e.g.
file://10.10.10.63/SharedDocs/archive.zip etc.
$Path = $(Read-Host "Enter Path and file pattern e.g. c:\zip\*.txt")
$Files = get-childitem $Path -include $Pattern -recurse
$FileNames = ""
foreach ($File in $Files)
{
write-host "File Name : $File " $File.LastWriteTime
$FileNames = $FileNames + " " + $File
}
write-host "Files to compress : " $FileNames
if($FileNames.Trim() -ne "")
{
powershell.exe -noexit "&'c:\program files\7-zip\7z'" a c:\target\archive.zip $FileNames
}
else
{
write-host "No files to compress :D"
}
Thursday, October 7, 2010
7-Zip command line
Download and install 7-Zip.
http://www.7-zip.org/
7z.exe a c:\a.7z "C:\Program Files"
compresses "C:\Program Files" completely, including all subfolders.
7z a c:\a.zip c:\dir\*.txt
compresses all files wih extension txt
7z.exe a c:\a.7z c:\file1.txt d:\dir2\file2.txt
compress multiple files at different locations
7z.exe e c:\test\archive.zip
extract all files to the current location
7z.exe e c:\test\archive.zip -oc:\test\AllFiles
extract all files to the specified path i.e. c:\test\AllFiles
http://www.7-zip.org/
7z.exe a c:\a.7z "C:\Program Files"
compresses "C:\Program Files" completely, including all subfolders.
7z a c:\a.zip c:\dir\*.txt
compresses all files wih extension txt
7z.exe a c:\a.7z c:\file1.txt d:\dir2\file2.txt
compress multiple files at different locations
7z.exe e c:\test\archive.zip
extract all files to the current location
7z.exe e c:\test\archive.zip -oc:\test\AllFiles
extract all files to the specified path i.e. c:\test\AllFiles
Powershell commands
This is an extract of what I have read here. http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/
Powershell commands are called Cmdlet (Command-Let).
get-command, List all powershell commands
get-command -verb Get, List all commands starting with word Get
get-command -noun service, List all commands ending with word service
get-help get-service, Get help for a particular command i.e. get-service
remove-item c:\test.txt, Removes the specified item
get-childItem c:\zip , Get items and subitems from a specified location
get-childItem c:\zip *.txt, Get all txt files from specified location
get-date , Get current date
======== Script to add 2 days to the current day ==========
$Now = Get-Date
$LastWrite = $Now.AddDays(2)
Write-Host $LastWrite
===========================================================
======= Display full path of file and last edited date time =============
$Files = $Files = get-childitem c:\zip -include *.txt -recurse
foreach ($File in $Files)
{
write-host "File Name : $File " $File.LastWriteTime
}
=========================================================================
PowerShell Comparison Operators:
Operator Description
-eq Equal to
-lt Less than
-gt Greater than
-ge Greater than or Eqaul to
-le Less than or equal to
-ne Not equal to
Powershell commands are called Cmdlet (Command-Let).
get-command, List all powershell commands
get-command -verb Get, List all commands starting with word Get
get-command -noun service, List all commands ending with word service
get-help get-service, Get help for a particular command i.e. get-service
remove-item c:\test.txt, Removes the specified item
get-childItem c:\zip , Get items and subitems from a specified location
get-childItem c:\zip *.txt, Get all txt files from specified location
get-date , Get current date
======== Script to add 2 days to the current day ==========
$Now = Get-Date
$LastWrite = $Now.AddDays(2)
Write-Host $LastWrite
===========================================================
======= Display full path of file and last edited date time =============
$Files = $Files = get-childitem c:\zip -include *.txt -recurse
foreach ($File in $Files)
{
write-host "File Name : $File " $File.LastWriteTime
}
=========================================================================
PowerShell Comparison Operators:
Operator Description
-eq Equal to
-lt Less than
-gt Greater than
-ge Greater than or Eqaul to
-le Less than or equal to
-ne Not equal to
Subscribe to:
Posts (Atom)