Posts

Showing posts from August, 2017

SQL Database back up scheduler in .ps1 code

$serverName = "WEBSVR1\WEBSVRSQL" $backupDirectory = "E:\Backup\MSSQL_Daily" $daysToStoreBackups = 2 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") | Out-Null [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum") | Out-Null $server = New-Object ("Microsoft.SqlServer.Management.Smo.Server") $serverName $dbs = $server.Databases Get-ChildItem "$backupDirectory\*.bak" |? { $_.lastwritetime -le (Get-Date).AddDays(-$daysToStoreBackups)} |% {Remove-Item $_ -force } "removed all previous backups older than $daysToStoreBackups days" foreach ($database in $dbs | where { $_.IsSystemObject -eq $False}) {            $dbName = $database.Name     ...

Download csv file in client side with mvc controller

1) This is controller action method public ActionResult FeedbackExport(List<string> guidList)         {             string fileName = "CDLmallFeedback.csv";             List<ContactUsViewModel> feedbackFullList = new ContactUsManager().GetAllFeedbackHistory().ToList();             if (guidList != null && guidList.Count() > 0)             {                 feedbackFullList = feedbackFullList.Where(x => guidList.Contains(x.GUID)).ToList();             }             string delimiter = ",";             int feedbackLength = feedbackFullList.Count();             StringBuilder sb = new StringBuilder();             sb.AppendLine(st...