Search Results:

Saturday, July 16, 2016

Simple Code to get First Day of Week and Last Day of Week

I wanted a simple and quick way to get the start of week and end of week to do some data processing for the week. Here is a simple three line code that can help achieve this.

        DateTime dt  = DateTime.Now();
        DateTime FirstDayofWeek = dt.AddDays(-(int)dt.DayOfWeek);
        DateTime LastDayofWeek = FirstDayofWeek.AddDays(6);

Hope it helps, Thanks!!!

Thursday, July 14, 2016

Get PageNames in SSRS for SubReports.


I was recently presented with a situation where i need to place chart on one sheet and data in other sheet when exported to excel in SSRS. I tried to use page break after the chart and inserted a sub report.

When i did that, i noticed that that page names cannot be set for sub reports. In order to acheive something like below. I looked at work arounds to make the page names as shown in below image.


I noticed that the PageName property is available one tablix and rectangles. So i just placed a rectangle and set its PageName as "Other Custom Name 1" and then insert the subreport within this rectangle control and then the exported excel sheet hast the custom names as expected.



Let me know if you  have any other work arounds or if you found this post helpful.

Thank you.

Tuesday, July 5, 2016

Difference between a KeyPress and KeyDown Events

The KeyDown event triggers for all the keys where as KeyPress only works for the character keys.

For example:

If you press Key A, then it will fire KeyDown as well as KeyPress event.

If you press Shift,Ctrl, Escape or BackSpace keys then only KeyDown is the only


Refer:MSDN Link

Thursday, June 16, 2016

Filter datatable using LINQ in VB.NET

Below is a simple LINQ that you can use to filter the DataTable.


AsEnumerable() method to return the input type DataTable as IEnumerable.

CopyToDataTable() method takes the results of the filtered query and copies into a new DataTable that you can use to work with the filtered data.

-------------------------------------------------------------------------
         Dim filteredTable As DataTable = (From n In dt.AsEnumerable()
                                           Where n.Field(Of Int32)("id") = 1
                                           Select n).CopyToDataTable()
-------------------------------------------------------------------------

Feel free to leave your comments or suggestions. Thank you.

Wednesday, October 30, 2013

Adding Handlers for Controls {Code}

Public Class Userdetails
Dim cnn As SqlConnection = New SqlConnection(My.Settings.ConnectionString)
Dim strSQL As String
Private pUserId As Integer
Private pNewUser As Boolean = False
Private IsDirty As Boolean = False
Private Sub AddSaveHandlers(ByVal c As Control)
For Each ctrl As Control In c.Controls
If ctrl.Controls.Count > 0 Then
AddSaveHandlers(ctrl)
End If
Select Case ctrl.GetType.Name.ToUpper
Case "TEXTBOX", "COMBOBOX"
AddHandler ctrl.TextChanged, AddressOf SetPromptSaveTrue
Case "CHECKBOX"
AddHandler CType(ctrl, CheckBox).CheckStateChanged, AddressOf SetPromptSaveTrue
End Select
Next
End Sub
Private Sub SetPromptSaveTrue(ByVal sender As System.Object, ByVal e As System.EventArgs)
IsDirty = True
End Sub
Private Sub Userdetails_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddSaveHandlers(Me)
End Sub
Private Sub Userdetails_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
Dim savedata As DialogResult
If IsDirty Then
savedata = MessageBox.Show("Do you want to save your changes?", "Save Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
Select Case savedata
Case Windows.Forms.DialogResult.Yes
Call btnSave_Click(sender, e)
Case Windows.Forms.DialogResult.Cancel
e.Cancel = True
Case Else
IsDirty = False
End Select
End If
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
End Class

VSS Writers and associated Services

Handreference linking VSS Writers to Services


VSS Writer Service Name Service Display Name

ASR Writer
VSS Volume Shadow Copy
BITS Writer BITS Background Intelligent
Transfer Service

COM+ REGDB Writer
VSS Volume Shadow Copy
IIS Config Writer AppHostSvc Application Host Helper
Service

IIS Metabase Writer
IISADMIN IIS Admin Service
Microsoft Exchange Writer MSExchangeIS Microsoft Exchange
Information Store
Microsoft Hyper-V VSS Writer vmms Hyper-V Virtual Machine
Management
Registry Writer VSS Volume Shadow Copy

Shadow Copy Optimization Writer
VSS Volume Shadow Copy

System Writer
CryptSvc Cryptographic Services

WMI Writer
Winmgmt Windows Management
Instrumentation

Thursday, October 17, 2013

Convert a Base64 String into a PDF File

Recently I had the need to decode a Base64 string and make a PDF of it.  Usually I would've written a small utility app, but this time I rolled with powershell: 

function decodeBase64IntoPdf([string]$base64EncodedString)
{
    $bytes = [System.Convert]::FromBase64String($base64EncodedString)
    [IO.File]::WriteAllBytes("C:\Users\medmondson\Desktop\file.pdf", $bytes)
}

I'm impressed with how quickly I can knock out a script like this (yes they are .NET assemblies) without having to load a new VS solution. Of course a lot more could be done to this (file format via an argument for example) but I thought I'd share it raw as I know I'll need to use it again one day.

From Matt's Blog