|
I am trying to send an email using my program. How Many ways are ther to do it? Which is the best way, currently i have:
Dim m As New MailMessage(FromtextBox.Text, ToTextBox.Text, SubjectTextBox.Text, BodyTextBox.Text)<br />
Dim a As New Attachment(My.Settings.CurrentList)<br />
Dim c As New SmtpClient<br />
m.Attachments.Add(a)<br />
c.Host = ""<br />
c.Send(m)
My main problem however is that i have no host info, is there anyway to access the host information on the machine the program is running on and, if not, is there an alternative, other than manuel user entry?
Posted by The ANZAC
|
|
|
|
|
If you don't have the host info, you need to use MAPI, there are .NET MAPI wrappers on the web.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
You make it sound easy, but i'm new to sending mail and have no idea about MAPI. Is there anyway to programatically extract Host Info or should I just add a user customisable setting to my program.
P.S. What Host Info is actually required to send an email, does it include password etc, or just the server.
Posted by The ANZAC
|
|
|
|
|
I've decided to go with having the user enter the server setting. Then its saved and is used automatically until changed.
Posted by The ANZAC
|
|
|
|
|
<code></code>I want datagrid code in which we r able to enter direct.for eg like in excel sheet we enter means we write in tables .same code want able to write directly in datagrid and then save that data
|
|
|
|
|
You must using dataset and binding it with datagrid
|
|
|
|
|
add ItemTemplates instead of normal columns in datagrid
Nana
|
|
|
|
|
Hello all!
I can't beleive I can't get this, but here it goes. I want to reset a integer number that used for a time. So at the top I have
Public mysec As Integer = 15
Then I have this for my timer
Private Sub tmrGame_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrGame.Tick<br />
Threading.Thread.SpinWait(1000)<br />
mysec = mysec - 1<br />
lblcdClock.Text = ":" & mysec<br />
If mysec > 15 Then<br />
mysec = 0<br />
End If<br />
If mysec = -1 Then<br />
tmrGame.Stop()<br />
lblcdClock.Text = ":" & 0<br />
Threading.Thread.Sleep(2000)<br />
lblcdClock.Text = ":" & 15<br />
End If<br />
End Sub
How can I reset "mysec" to 15 so when the time stops, and I start it agin, it start from 15? Using VS 2003.
Thanks!
Rudy
|
|
|
|
|
The method that starts the timer should reset the variable.
rudemusik wrote: If mysec = -1
if mysec < 0 is a safer check to make, just in case.
So, if it goes over 15, it gets reset to 0, and on the next iteration, it will end ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi Christian!
It's actually counting down from 15. I have mysec = -1 so that a 0 will show. After the 0 shows, I set the label to 15. But it doesn't change my intger, so if it starts again, it will start with -1, -2 and so on. How can I change the 0 to a 15 as if if I were reloading the form to kick off the "Public mysec As Integer = 15" line.
Thanks!
Rudy
|
|
|
|
|
'Resetting' the value is as simple as mysec = 15, you should do this just before you start the countdown.
|
|
|
|
|
Thanks Everybody!
I finally got it. I actually had to put "mysec = 15" at the end of the countdown.
Thanks again!
Rudy
|
|
|
|
|
keep all your code inside inner loop and when the loop will end assign mysec=15
enclose this also inside an outer loop
.use 2 while loop this will be better and give terminating condition in outer while loop
ok
prem kumar singh
|
|
|
|
|
Hi Lucky!
What do you ean by inner loop?
Thanks!
Rudy
|
|
|
|
|
Hi all,
I'm working on the following problem with VB2005: An application (which is not under my control) appends a new line of information to a logfile (*.txt) once per second. A filesystemwatcher raises an event any time the filesize has changed. I have to open the file, read the last line of new information and close the file immediately to allow the next line to be written by 'the other' software.
The problems:
1. The log file is big and becomes bigger every second. So I want to avoid reading the complete file and throw everything away except of the last new line. Has anyone got an idea, how to make a slim 'last-line-reader'?
2. It seems, that the file is not closed after reading immediately, which corresponds to what I find in several books. Any chance to close a file again immediately?
Thanks to all, bodobe
|
|
|
|
|
What are you doing with this information that you would need to save it every second then read it from another watcher program when it changes??
Cleako
|
|
|
|
|
Hi,
'the other software' is the frontend of a measurement system writing measurement data continuously (well, nearly - once per second). It's a closed system with no other access to the measurement data, postprocessing is supposed to be done via Excel. I started writing a 'real time postprocessing' for this application - that's why and what for I have to use this workaround.
Best regards, bodobe
|
|
|
|
|
Does the log file need to exist indefinitely or just until the post processor works with it?
Cleako
|
|
|
|
|
Once I have read the data lines into my software, I can write a new logfile. So the original logfile is no longer required.
BR, bodobe
|
|
|
|
|
You could do that then. Create a new file for each entry. In the post processor always start from the oldest file, read it in, then delete it after closing the file. That way you are never attempting to read a file you are writing to or the other way around.
Cleako
|
|
|
|
|
 I think you can use the a FileStream object to randomly access a file. Here is some code for you to look over. I added a button to the form and when you click the button a messagbox appears displaying the last text to be added to a text file. It keeps track of the last position read so the next time it reads the file it can begin reading it from the last position read. To test it just create a file "c:\test.txt". Run the application and then modify the text file and save it. Clicking the button should display the text you entered. Open the file again and add another line and save it. Again clicking the button should show you the new line of text.
Public Class Form1
Dim index As Long = -1
Const file As String = "c:\test.txt"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'FileInfo object so we can get the file size
Dim info As New IO.FileInfo(file)
'How many new bytes since we last checked
Dim count As Long = info.Length - index
'File hasn't changed so return
If count <= 0 Then Return
'File stream to read file
Dim stream As IO.FileStream = IO.File.Open(file, IO.FileMode.Open, IO.FileAccess.Read)
'Buffer to retrieve bytes
Dim buf(count) As Byte
'Set the streams position to where we last left off
stream.Position = index
'Read the new bytes
stream.Read(buf, 0, count)
'clean-up so we don't get in the way of the other program
stream.Close()
stream.Dispose()
'Decoder to convert byte array to string
Dim textDecoder As New System.Text.ASCIIEncoding
'The new text
Dim str As String = textDecoder.GetString(buf)
'Display new text
MsgBox(str)
'Set index to next position
index = info.Length
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Initialize index to the last position in the file
Dim info As New IO.FileInfo(file)
index = info.Length
End Sub
End Class
|
|
|
|
|
Hi, thanks a lot, works great! I only had to place the IO.File.Open(...) into a Try..Catch, because the FileSystemWatche raises the FileChanged-Event a bit too early: File has been changed, but not yet been closed by the other software.
While LogReadPermission <> True
Try
stream = IO.File.Open(LogFile, FileMode.Open, FileAccess.Read)
LogReadPermission = True 'if stream has been opened without exception, allow reading and leave 'while'
Catch ex As Exception
Threading.Thread.Sleep(5) 'short wait before next try
i += 1
If i > 100 Then
MsgBox("Logfile not found! " & ex.ToString)
End If
End Try
End While
stream.Position = Index
stream.Read(buf, 0, count)
...
|
|
|
|
|
Your welcome, glad it's working for you. I messed around with the code after I posted it. I also added a try catch block around the IO.File.Open and looped until it was a success with a small wait in between each attempt. Looks like with think a like. Just so you know retrieving the FileInfo object will succeed even if the file doesn't exist. However, if you try to read the file size and the file doesn't exist it will throw an error which would crash your program if you didn't handle it. The info object can actually tell you if the file exists. I check this and leave the procedure if we have no file. This is how I handled it.
Do
'Get the most up to date information
info = New IO.FileInfo(file)
'If file doesn't exist leave
If Not info.Exists Then Return
'info.length throws an error if the file doesn't exist, thus the needed line above.
count = info.Length - index
Try
stream = IO.File.Open(file, IO.FileMode.Open, IO.FileAccess.Read)
Catch ex As Exception
'Sleep a little and try again later
Threading.Thread.Sleep(5)
End Try
Loop While stream Is Nothing
I like your counter to keep track of attempts and respond if there are too many. That's odd that the file isn't ready for reading after the FileSystemWatcher raises the event. I simulated your situation and did a stress test for 3 minutes and it never failed to open the file. Maybe it has to do with the file size. I started from scratch so the file was pretty small.
Just out of curiosity does this logfile ever get cleared? A line a second has to add up.
|
|
|
|
|
One suggestion, if you program by exception your app will slow down tremendously. If you can find a way to avoid having it throw the exception in order for you to know when to try to access again then you should.
CleAkO
|
|
|
|
|
Hello.
I've already made my own form to use a GUI to search for a specific folder to save information to, but I was wondering if anyone knew a way to use the CommonDialog to do this?
Currently, I can only get the CommonDialog to save to a specific file. What I want is for my user to be able to search and pick a specific folder. I just want to use the Common Dialog box to return the path to that folder.
Is there any way to do this or should I just stick with my homemade method?
Thank you!
|
|
|
|