VB.NET to Delete files older than 30 days from folder

So, I wrote a comparison logic that would check the individual file to 30 days old with DateTime.Compare and wanted to share it in case it helps someone.
I display the deleted file, the date it was created as well as the files which aren’t deleted with their creation date in two lists in the ASPCA page. Btw this is in VB.NET

For Each aFile In Files
Try
Dim beforeThisDate As Date = DateAndTime.Today.AddDays(-30)
Dim thisFileModifiedDate As Date = System.IO.File.GetLastWriteTime(strFilePath & aFile.ToString())
Dim htmlNewLine As String = “

Dim result As Integer = DateTime.Compare(thisFileModifiedDate, beforeThisDate)
If result < 0 Then
'MsgBox(thisFileModifiedDate + " Is earlier than " + beforeThisDate)
lblDeletedFiles.Text += aFile.ToString + " Date created:" + thisFileModifiedDate + htmlNewLine
deleteCount = deleteCount + 1
System.IO.File.Delete(Folder + aFile.ToString())
ElseIf result = 0 Then
'MsgBox(thisFileModifiedDate + " Is the same as " + beforeThisDate)
lblNotDeletedFiles.Text += aFile.ToString + " Date created:" + thisFileModifiedDate + htmlNewLine
notDeletedCount = notDeletedCount + 1
Else
'MsgBox(thisFileModifiedDate + " Is later than " + beforeThisDate)
lblNotDeletedFiles.Text += aFile.ToString + " Date created:" + thisFileModifiedDate + htmlNewLine
notDeletedCount = notDeletedCount + 1
End If
Catch ex As Exception
LcpsUtilities.RecordError(ex.Message, "RecycleIcsEvents.delete file section")
End Try
lblDeletedCount.Text = deleteCount.ToString
lblNotDeletedCount.Text = notDeletedCount.ToString
Next

The files on the folder that are older than 30 days are now deleted.
Good luck !

Find your .NET project type.

Find your .NET project type.

Ever wanted to find out what type of project it is you are working with? Or wanted to create a new project of the same type but had no clue if it was a Web application?

Easy way to do that would be to go to your project folder -> Right click the (.vbproj/.csproj) and open it with any text editor (notepad).

Now if you have an element for GUID for instance {349C5851-65DF-11DA-9384-00065B846F21} go to the link above and find out what its corresponding type is.

This example is a Web Application project.

Good luck!

Reporting Services report parameter NULL value

Issue: Unable to pass NULL value to the parameter of a report through URL from .NET code.
Solution: In the url add the parameter isNull = true in order to make it accept null value and display the report.
Here is what i had to do, I had a report with 2 parameters. State, Counties.
When I click on a State on the map I wanted to see the report filtered by the selected State and all its counties.
When I click on a county I wanted to see the report filtered by both state and county.
so after creating the report and modifying the dataset as per this article “http://bloggingabout.net/blogs/egiardina/archive/2007/06/26/sql-server-reporting-services-optional-parameters.aspx?CommentPosted=true#commentmessage&#8221;
I appended parameter2:isNULL=True when the parameter2 was not passed.
When it was passed, i gave parameter2=value;
Worked like a charm!
Good luck!

Get the Server name and SQL instance name in ToolPart (c#)

Requirement: ServerName and InstanceName to be displayed in a ToolPart

Data: The classes required to retrieve the DataSource(this contains the server name and instance name used in the connection string) using ASP.NET are,

SqlConnection, SqlCommand

Solution:

public string RetrieveDataSource

{

get

{

SqlConnection sqlConnection = new SqlConnection(this.CurrentConnectionString); SqlCommand sqlCmd = new SqlCommand(); sqlConnection.Open();

sqlCmd.Connection = sqlConnection; return “Server Name :” + sqlCmd.Connection.DataSource;

}

}

Conclusion: The above code returns the DataSource in the following format “MyServerName\SQLInstanceName”