Friday, September 19, 2008

Problem Opening SharePoint Server Alert in Outlook 2007

This problem occurs because Exchange 2003 cannot convert the MIME-type properties to MAPI-type properties correctly if the names of the properties begin with X-.

You cannot open a SharePoint Server 2007 notification message in Outlook 2007 when your mailbox is on an Exchange 2003 server.

The hotfix is available via customer support. The hotfix applies to Exchange Server 2003 and has to be applied after it has been upgraded to SP2.

http://support.microsoft.com/kb/930807/en-us

Friday, September 12, 2008

Send Mail with Asp.Net {C#}

//1. Send Simple Mail in Asp.Net without any credentials (Host, Username or password)

using System.Net.Mail;

public static void SendMail(string From, string To, string Body, string Subject)
{
SmtpClient objSmtpClient = new SmtpClient();

// Give SMTP Server name here.
objSmtpClient.Host = ConfigurationManager.AppSettings["SmtpServer"].ToString();
objSmtpClient.Port = 25;

MailMessage objMailMessage = new MailMessage();
MailAddress objMailAddress = new MailAddress(From);
objMailMessage.From = objMailAddress;
objMailMessage.To.Add(To);
objMailMessage.Subject = Subject;
objMailMessage.IsBodyHtml = true;
objMailMessage.Body = Body;
objMailMessage.Priority = MailPriority.High;

objSmtpClient.Send(objMailMessage);
}

//2. Send Mail in Asp.Net with credentials (Host, Username or password)

using System.Net.Mail;

public static void SendMail(string From, string To, string Body, string Subject)
{

// give SMTP Server Host name or IP Address.
SmtpClient objSmtpClient = new SmtpClient(”HostNameOrIP”);

MailMessage objMailMessage = new MailMessage();
MailAddress objMailAddress = new MailAddress(From);
objMailMessage.From = objMailAddress;
objMailMessage.To.Add(To);
objMailMessage.Subject = Subject;
objMailMessage.IsBodyHtml = true;
objMailMessage.Body = Body;
objMailMessage.Priority = MailPriority.High;

// Give your SMTP Server UserName and Password
objSmtpClient.Credentials = new System.Net.NetworkCredential(”UserName”, “Password”);

objSmtpClient.Send(objMailMessage);

{C#} Simple Encrypt and Decrypt String

//Encrypt Method

private string EncryptString(string strSource)
{
Byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes(strSource);
string encryptedString = Convert.ToBase64String(b);
return encryptedString;
}

// Decrypt Method

private string DecryptString(string strSource)
{
Byte[] b = Convert.FromBase64String(strSource);
string decryptedString = System.Text.ASCIIEncoding.ASCII.GetString(b);
return decryptedString;
}

C# Convert String into Proper Case

Convert a string to Proper Case
===========================

// Use this Namespace
using System.Globalization;
// Code
string myString = "jEssE PaTricio-jR";
TextInfo TI = new CultureInfo("en-US",false).TextInfo;
Response.Write (TI.ToTitleCase( myString ));

Thursday, September 4, 2008

Connection String - Using sqlDataReader

It's been awhile since my last post. Now I'm currently doing some asp .net projects again and I can't remember the connection string and commands I've previously used to manually connect and get data from my source, hence, I would post it here as a reference so I don't have to search again and again for the source code.

Assuming that i have my sql server connectionstring configured on my web.config file and my stored procedure named "valStudentProfile" with two varchar parameters "username" and "password" created on my SQL Server 2005.

VB Code

Imports System.Data.SqlClient

'-- this function will validate user and return true or false
'-- by calling stored procedure and passing parameters.

Function AuthenticateUser(ByVal Username As String, ByVal Password As String) As Boolean

Dim oConn As New SqlConnection

oConn.ConnectionString = ConfigurationManager.AppSettings("MyServerName")
oConn.Open()

Dim oComm As New SqlCommand
oComm.Connection = oConn

oComm.CommandType = CommandType.StoredProcedure
oComm.CommandText = "valStudentProfile"

Dim pUser As New SqlParameter("@username", SqlDbType.VarChar)
Dim pPass As New SqlParameter("@password", SqlDbType.VarChar)

pUser.Value = UserName.ToString()
pPass.Value = Password.ToString()

oComm.Parameters.Add(pUser)
oComm.Parameters.Add(pPass)

Dim rd As SqlDataReader = oComm.ExecuteReader()

rd.Read()

'- validate if have records
If rd.HasRows Then
'- initialize my session variable
Session("userid") = rd.Item("userid").ToString()
'return true if record exist in the database
Return True
Else
'- return false if no record found match
Return False
End If
-- disposing objects
oComm.Dispose()
oConn.Dispose()
End Function


C# Code


public authUser()
{
string username = txtUsername.ToString();
string password = txtPassword.ToString();

SqlConnection oConn = SqlConnection(ConfigurationManager.AppSettings["MyServerName"]);
conn.open();

SqlCommand oComm = new SqlCommand("valStudentProfile", oConn);

oComm.CommandType = CommandType.StoredProcedure;
oComm.Parameters.Add("@username", SqlDbType.VarChar).Value = username;
oComm.Parameters.Add("@password", SqlDbType.VarChar).Value = password;

SqlDataReader rd = oComm.ExecuteReader();

if (rd.Read())
{
return true;
} else {
return false
}
}