Tuesday, January 11, 2011

How to change the expiration date of certificates- ClickOnce .pfx file

Certificate (.pfx file) is use to sing your “ClickOnece” application. It has expiration date. By default first publish allows one year time period as expiration date. Mean time you can publish several version of your “ClickOnce”. Once certificate get expired visual studio not allows publishing “ClickOnce” application. You have to re-create a certificate and publish again. But the entire client machines which are using your application have to uninstall application and reinstall it again. This is not faire if you have number of clients.

Here is the solution to extend expiration date of certificate.

Using RenewCert.exe file. Here is the command to renew certificate.

Renewcert [PFX File] [new cert filename] [new cert friendly name] [optional] [password]

Example :

Renewcert oldcert.pfx newcert.pfx “CN=MyNewCert” MySuperSecretPassword

Blogs say RenewCert.exe file is come with Windows SDK , VS 2010 , but I could not find it after install SDK or VS 2010 (C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin) . Click here to download the file.

Tuesday, January 12, 2010

Send an Email via your own host - vb.net

'create instance of MailMessage

Dim mailMessage As New MailMessage()

Try

set smtp authntication for your host- this must have username(full email address. Ex admin@myhost.com) and password which is already registerd in your host

mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1)

mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "admin@myhost.com")

mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "adminpassword")

'set send from email addrss

mailMessage.From = "fromemail@myhost.com"

'recipient's email address

mailMessage.To = "ruwansj@gmail.com"

'email address of the Cc recipient

mailMessage.Cc = ""

'email address of the Bcc recipient

mailMessage.Bcc = ""

'subject of the email message

mailMessage.Subject = "Hello"

'message text format. Can be text or html

mailMessage.BodyFormat = MailFormat.Text

'message body (if you suppose to use html as bodyformat, then you have to use html tags for create mail message.

mailMessage.Body = "Test email for vb.Net ."

'email priority. Can be low, normal or high

mailMessage.Priority = MailPriority.Normal

'mail server used to send this email. modify this line based on your mail server

SmtpMail.SmtpServer = "mail.myhost.com"

'using the static method "Send" of the SmtpMail class to send the mail

SmtpMail.Send(mailMessage)


Catch ex As Exception

Response.Write(ex.Message)

End Try

Saturday, January 9, 2010

Console Application for Read and Compare a letter in text file

Module Module1
'This can use to read list of names in a text file

Sub Main()
Dim txt As String
Dim oFile As System.IO.File
Dim oRead As System.IO.StreamReader
oRead = oFile.OpenText("C:\sample.txt")


While Not oRead.EndOfStream
'do whatever you want to do
txt = oRead.ReadLine()
Console.WriteLine(txt)

'read text input charactor to be compare

Dim compChar As Char()

compChar = "d"

If compChar = txt.Substring(0, 1) Then
Console.Write("Charactor Found : " & txt)
Console.WriteLine("")
End If

End While

oRead.Close()
Console.ReadKey()

End Sub

End Module




'-------------- Out put ---------------Sample text in sample.txt
Ruwan
daya
Kamal
jagath
Nimal
Rasika
Manoj