Copy a file in the file system Supply a source file name and the destination file name CopyFile(“c:\temp\firstfile.txt”, c:\temp\secondfile.txt”) Function Copyfile(ByVal sSource As String, ByVal sDest As String) As Boolean FileCopy(sSource, sDest) If Err.Number = 0 Then Copyfile = True End Function
Here is a simple snippet to get the selected text of the list box in vb.net Make use of the SelectedIndexChanged Event of the listbox and add the following code in it Private Sub lstBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstBox.SelectedIndexChanged Me.lblCategory.Text = Me.lstBox.GetItemText(Me.lstBox.SelectedItem) End Sub
The following function returns the file extension only. eg. using the following function GetFileExtension(“c:\test\file.aspx”) will return “.aspx” Here is the complete function, copy and paste it in your form or a module Function GetFileExtension(ByVal sFilePath As String) As String ‘ Dim fullPath As String = “c:\MyDirectory\MYFile.txt” Dim sExtension As String = IO.Path.GetExtension(sFilePath) Return (sExtension) End […]
How to generate a random number in vb.net Function GenerateRandomNumber(iLowerRange As Integer, iUpperRange As Integer) as integer Dim RandomGenerator As Random Dim intRandomNumber As Integer RandomGenerator = New Random() ‘Get the next random number intRandomNumber = RandomGenerator.Next(iLowerRange, iUpperRange+ 1) ‘Return the random # as the function’s return value return intRandomNumber End Function
The standard install file contains ,htaccess file. If you have copied this file to your website folder then remove it as IIS does not make use of the .htaccess. This error will be fixed once you remove the.htaccess.
This function will decode the mime data contained in a string into a BYTE and then it can be saved onto your desktop using the FileStream. ————————————————————————- Dim byteData As Byte() byteData = FromBase64(strMimeData) Dim oFileStream As System.IO.FileStream oFileStream = New System.IO.FileStream(“c:\temp\” & Me.txtAttachFileName.Text, System.IO.FileMode.Create) oFileStream.Write(byteData, 0, byteData.Length) oFileStream.Close() This function will encode the data […]
Here is a working code for changing the DataGridView row colors based on condition. In this code I am checking if the Cell called “Date Closed” is present or not, so if a row item has a closed date present then I would like to show that row in Red Color. It is easy to […]
DataGridView columns widths can be adjusted automatically to ensure that the full display area is used. In column fill mode, the DataGridView control resizes its columns automatically so that they fill the width of the available display area. In the Properties of your DataGridView Change the AutoSizeColumnMode to FILL