VB.net check for existence of files and or folders


Add this to check the existence of a particular file:
Dim sFileName As String
sFileName = “C:/text1.txt”
Dim fFile As New FileInfo(sFileName)
If Not fFile.Exists Then
MessageBox.Show(“File Not Found”)
Else
MessageBox.Show(“File Found. File was created on: ” & fFile.CreationTime)
End If

Add this to check the existence of a directory:
Dim sDirName As String
sDirName = “C:/temp”
Dim dDir As New DirectoryInfo(sDirName)
If Not dDir.Exists Then
MessageBox.Show(“Directory Not Found”)
Else
MessageBox.Show(“Directory Found. Directory was last accessed on: ” & dDir.LastAccessTime)
End If

Could not load file or assembly error


My computer blue-screened in the middle of a build of a website I’m working on from Microsoft Visual Studio.  When it finished rebooting I couldn’t load my local copy of the website and I kept getting the following error when trying to view the site from my browser: “Could not load file or assembly….” the actual error message was a whole page long.

I grabbed a backup and restored the files, no luck.  I restarted IIS, no luck.

A couple of Google searches later and I found this site with the following instructions:

Delete all temporary ASP.NET files, by removing the folders under the following directory and then check it:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET files\

Just like that it started working again!

Generate random numbers in VB 2005

Maybe common knowledge for some, but I’m not a full time programmer so sometimes the smallest things make my day.

Dim myRandomNumber As Integer = rnd.Next(1000, 999999)

So, this code generates a random number between 1000 and 999999.

How to pass parameters to an asp hyperlink from within a Gridview – Visual Studio 2005

code
I figured I’d post this because I’ve been wrestling with it for hours now.

<asp:HyperLink ID=”HyperLink1″ runat=”server” NavigateUrl='<%# “makeappointment.aspx?SiteId=” + DataBinder.Eval(Container.DataItem,”accountid”).tostring + “&Date=” + DataBinder.Eval(Container.DataItem,”drivedate”,”{0:d}”).tostring%>’>Make Appointment</asp:HyperLink>

This gives you a hyperlink that looks like:

http://localhost/donor/makeappointment.aspx?SiteId=875&Date=1/23/2008

Notice on the date item I added the ,”{0:d}”
This formats the date to a short date with no time.

Sometimes the silliest things can take forever to figure out.
Maybe it had something to do with my kids running around my office. Right after they left I got this working!
Note: I don’t claim to be a uber programmer. If you are one, feel free to tell me my code is crap! I just shoot for what works for my needs.  Also, WordPress does some funky stuff when you post code, so some of the quotes might get messed up when you copy and paste.  I need to figure out how to post programming code without it getting all messed up.