.NET | Suhail Kaleem

.NET

Get months list between two dates

0

Following function  will  get a list of months  with days remaining in those months  when start date and end dates are provided


Shared Function GetMonthsList(StartDate As Date, EndDate As Date) As ArrayList

Try

Dim dt As Date = StartDate
Dim edt As Date = EndDate

Dim ar As New ArrayList
Dim str As New StringBuilder

While dt < edt

str.Append(dt.Date.ToString("MMMM yyyy"))
str.Append(",")
Dim dt2 As Date = dt.AddMonths(1)

If dt2 > edt Then
Dim minusdays As Integer = DateDiff(DateInterval.Day, dt, edt)
str.Append(minusdays + 1)
ar.Add(str.ToString)
Exit While
End If

Dim remainingdays As Integer = System.DateTime.DaysInMonth(dt.Year, dt.Month) - dt.Day
str.Append(remainingdays + 1)

ar.Add(str.ToString)
dt = dt.AddDays(remainingdays + 1)
str.Clear()
End While

Return ar

Catch ex As Exception
Throw ex
End Try
End Function

Use can use this functions as


GetMonthsList(Date.Parse("1/4/2012"),Date.Parse("4/30/2012"))

this will output

January 2012,28
February 2012,29
March 2012,31
April 2012,30

How to fully trust a asp.net application (using command line and GUI )

0

Some server do not have “Microsoft .NET Framework 2.0 Configuration” in there administrative Tools

they can use CasPol.exe to Fully Trust a website.

Please run the following code in command line.
%windir%\Microsoft.NET\Framework\v2.0.50727\caspol -quiet -m -ag All_Code -url “http://localhost/*” FullTrust

 

you can also download .NET Framework 2.0 Software Development Kit (SDK) to install  Microsoft .NET Framework 2.0 Configuration

and you can trust a website using the GUI  like below

 

1.     From the Start menu, point to Administrative Tools, and then click Microsoft .NET Framework 2.0 Configuration.

If you don’t have Administrative Tools on the Start menu, from the Control Panel open Administrative Tools, and then double-click Microsoft .NETFramework 2.0 Configuration.

2.     Under My Computer, expand the Runtime Security Policy node, the Machine node, Code Groups node, the All_Code node, and then right-click the All_Code node and click New to open the Create Code Group dialog box.

3.     Name the new code group 'MY WEB APPLICATION NAME', and then click Next.

4.     Select a ‘Site’ membership condition from the drop down box

5.     Under ‘Site name’ type in  the URL to my web application

6.     Give ‘FullTrust’ permission set and click Finish

7.     To apply the new settings, close and restart your browser

 

Function to format dateTime to RSS 2 pubDate

0

The following vb.net function will format the date-time  to pubDate format for rss 2

Private Function BuildPubDate(ByVal d As Date) As String
Try
Dim RV As String
Dim day As String = d.Day.ToString
If day.Length = 1 Then day = "0" &amp; day
Dim month As String = d.Month.ToString
Select Case month
Case "1"
month = "January"
Case "2"
month = "February"
Case "3"
month = "March"
Case "4"
month = "April"
Case "5"
month = "May"
Case "6"
month = "June"
Case "7"
month = "July"
Case "8"
month = "August"
Case "9"
month = "September"
Case "10"
month = "October"
Case "11"
month = "November"
Case "12"
month = "December"
End Select

Dim Mtime As String = ""
Dim mDate As Date = d.ToUniversalTime
If mDate.Hour.ToString.Length = 1 Then
Mtime = "0" &amp; mDate.Hour.ToString
Else
Mtime = mDate.Hour.ToString
End If
Mtime += ":"
If mDate.Minute.ToString.Length = 1 Then
Mtime += "0" &amp; mDate.Minute.ToString
Else
Mtime += mDate.Minute.ToString
End If
Mtime += ":"
If mDate.Second.ToString.Length = 1 Then
Mtime += "0" &amp; mDate.Second.ToString
Else
Mtime += mDate.Second.ToString
End If

RV = d.DayOfWeek.ToString.Substring(0, 3)
RV += ", " &amp; day &amp; " " &amp; month.Substring(0, 3)
RV += " " &amp; d.Year.ToString &amp; " " &amp; Mtime &amp; " GMT"
Return RV
Catch ex As Exception
Return ""
End Try
Go to Top