|
Check out the System.IO.Directory class, it'll do the counting stuff for you.
|
|
|
|
|
There is no import for the FileSystemObject. You would normally have to set a reference to the Windows Scripting Host. But, it's pointless to do this under the .NET Framework.
Scrap this code and rewrite it using the classes in the System.Io namespace. The FileSystemObject is not needed in VB.NET. Also, the return type, Long in VB6, is a 32-bit signed interger. In VB.NET, this same Long datatype name is a 64-bit signed integer. Be careful when translating VB6 code to VB.NET.
Imports System.Io
.
.
.
Public Shared Function GetFileCount(ByVal folderPath As String) As Integer
If Not Directory.Exists(folderPath) Then
Throw New DirectoryNotFoundException("The specified path was not found.")
End If
Dim filenames As String()
filenames = Directory.GetFiles(folderPath)
Return filenames.Length
End Function
|
|
|
|
|
Try using the System.IO functions rather than using the old VB6 functions. When you are coding in .Net you should always look for the new ways to do things rather than the old VB6 functions, you never know when they are going to cease to exists, so you might as well conform now.
<br />
Imports System.IO<br />
<br />
<br />
Private Function GetFileCount(Byval path as String) as Integer<br />
Dim dirInfo As New IO.DirectoryInfo(path)<br />
Dim files() As FileInfo = dirInfo.GetFiles()<br />
return files.GetUpperBound(0) + 1<br />
End Function<br />
Mike Lasseter
|
|
|
|
|
I am trying to insert an exception in an access table. The exception is 'Access to the path 'C:\System Volume Information' is denied." I want this exception to be entered into a table while the program continue to scan for files. However, when I try to insert the exception into the db table I keep getting the error Syntax error (missing operator) in query expression "Access to the path 'C:\System Volume Information' is denied."
Here is my code:
Try<br />
Dim fileName As String<br />
patterns = Array.ConvertAll(patterns, New Converter(Of String, String)(AddressOf ConvertFilters))<br />
ListBox1.BeginUpdate()<br />
ListBox1.Items.Clear()<br />
For Each folder As String In enteredFilePaths<br />
For Each file As String In My.Computer.FileSystem.GetFiles(folder, FileIO.SearchOption.SearchAllSubDirectories, patterns)<br />
fileName = System.IO.Path.GetFileName(file).ToLower<br />
If ListBox2.FindStringExact(fileName) = -1 Then<br />
ListBox1.Items.Add(fileName)<br />
End If<br />
Next<br />
Next<br />
ListBox1.EndUpdate()<br />
Catch ex As Exception<br />
ErrorLog(ex.Message)<br />
End Try
Private Sub ErrorLog(ByVal Exception As String)<br />
Dim myConnString As String = "Provider=Microsoft.Jet.OleDB.4.0;Data Source=" & Application.StartupPath & "\File.mdb"<br />
Dim myInsertQuery As String = "INSERT INTO tblErrorLog (Error) VALUES ('" & Exception & "')"<br />
Dim myConnection As New OleDbConnection(myConnString)<br />
Dim command As New OleDbCommand(myInsertQuery, myConnection)<br />
Dim retvalue As Integer<br />
<br />
myConnection.Open()<br />
retvalue = command.ExecuteNonQuery<br />
<br />
'Close database connection<br />
myConnection.Close()<br />
<br />
End Sub
jds1207
|
|
|
|
|
Escape the single quote and then insert.
|
|
|
|
|
Use parameterized queries to do the update and you won't have to worray about escaping anything. It'll be done for you. Read[^] for more information and other reasons why it's a good idea to use parameters instead of string concatenation.
|
|
|
|
|
i am using vb.net 2003.i am doing my project in vb.net windows application.the following code is for sending mail.
Dim mymailmessage As New MailMessage
Try
Dim bSuccess As Boolean = True
mymailmessage.From = FromTextBox.Text
mymailmessage.To = "kumar@indocanapparel.com"
mymailmessage.Bcc = sb.ToString
mymailmessage.Subject = SubjectTextBox.Text
mymailmessage.Body = MessageTextBox.Text
mymailmessage.BodyFormat = MailFormat.Text
mymailmessage.Priority = MailPriority.Normal
SmtpMail.SmtpServer = "127.0.0.1"
SmtpMail.Send(mymailmessage)
DisplayLabel.Text = "Your Mail was Successfully Sent"
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
the above code,i written in vb.net windows application.
i run the project,then i click send button means,the following error is display.
"Could not access 'CDO.Message' object"
how to solve this?plz help.
|
|
|
|
|
|
Hi, I’m new to programming so bear with me on this...
Basically my program uses reporting services to send out reports to customers, each report needs pre specified values before it can run (Year, Customer name ect). At the moment I can connect to reporting services and get the parameters name and its Prompt ect back. But what I want is the parameter values (e.g. The parameter is Year I want my program to return all the values in the "Year" drop down box).
Sorry if this isn’t to clear but any help would be grate I’ve been stuck on this for a day or so now!
Cheers,
Rene
|
|
|
|
|
i was generating an exe of my window project. whenever i try to deploy it on the machine - not having the dot net 2.0 framework - it shows a messagebox to install the dot net framework.
I initially added the framework but still getting errors.
I think i am somewhere missing something.
can somebody send the deployment steps ?
|
|
|
|
|
Nilish wrote: I initially added the framework but still getting errors.
What error?
Regards,
Satips.
|
|
|
|
|
I think i have mentioned the error in my query.
|
|
|
|
|
Did you add the 2.0 framework. If you added the 1.1 framework for a 2.0 app you would still get errors. The other possibility is if you are installing the app and you are not an admin on the PC you are installing it on you may get some security errors.
Ben
|
|
|
|
|
sir,
error initiates when i double click my setup file.The error message is ... The dot net framework is not installed.i am mounting 2.0 framework.
Can u send me the installation steps (especially for adding the dot net framework)
|
|
|
|
|
|
Hi all
how to accomplish email validation in windows application
Thanks in advance
PraveenKumar Palla
-- modified at 9:39 Friday 22nd June, 2007
|
|
|
|
|
|
Really i am verry sorry
i need email validation in windows application
|
|
|
|
|
The email address format validation is normally done by a regular expression. The link he posted was kind of accurate, but since it's a C++ article, it may be difficult to understand.
This code was taken from this article[^] and converted to VB.NET.
Imports System.Text.RegularExpressions
.
.
.
Public Shared Function EmailAddressIsValid(ByVal address As String) As Boolean
Dim strRegex As String = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" & _
"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" & _
".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
Dim re As New Regex(strRegex)
If re.IsMatch(address)
Return True
Else
Return False
End Function
|
|
|
|
|
|
Try something like the following:
<br />
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
Dim objRegEx As New System.Text.RegularExpressions.Regex("^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$")<br />
If objRegEx.IsMatch(TextBox1.Text) Then<br />
ErrorProvider1.SetError(sender, "")<br />
Else<br />
ErrorProvider1.SetError(sender, "Email address is not valid")<br />
End If<br />
End Sub<br />
You may have to adjust the regex depending on what you consider a valid email address.
|
|
|
|
|
whenever I am generating EXE of our vb.net project then all those crystal report that is generated using through data set are not proprly running on other system but running fine on same system .
MARA !DEA
|
|
|
|
|
hi,
what problem occur on other system ?
describe the problem which is occur on other system.
without any proper indication how can anybody help you?
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
|
|
|
|
|
Probably because you didn't install the Crystal Reports runtime when you created your application's installer. Read more here[^].
|
|
|
|
|
How are you deploying your application to the other system? If you are just moving the EXE you are probably missing the Crystal dependency files. Create a Setup project for your app, it will grab all of the needed files and install them on the other system.
|
|
|
|