06/24/2008

Configuring Windows XP for Chinese Language Input



Windows XP comes with built-in support for inputting languages other than English. As a Singaporean Chinese, I am thrilled that I can input Chinese characters into my applications, such as Word, Notepad, and even my .NET applications.

Here is how you can configure Windows XP to support the Chinese language:

Figure 13. Installing the Chinese language support
4. Click OK. Windows XP will install the necessary files for the new languages. You will need your Windows XP installation disk.
5. Windows will restart.
6. After the restart, go back to the same window (as shown in Figure 13) and click on the Details... button.
7. The Text Services and Input Languages window will be displayed, as shown in Figure 14.



8. Click the Add... button to display the Add Input Language window (see Figure 15).



9. Select "Chinese (PRC)" as the input language and select "Chinese (Simplified) - Microsoft Pinyin IME 3.0" as the keyboard layout/IME. Click on OK.

10. Under the Installed services group, select the "Chinese (Simplified) - Microsoft Pinyin IME 3.0"service and click on the Properties... button (see Figure 16).



11. In the Conversion mode group, select "Sentence". In the Candidate option group, check the "Prompt step by step" checkbox (see Figure 17). Click OK.



12. You should now see the language bar displayed in the Taskbar (see Figure 18).



13. To switch to Chinese input, you can either use the Taskbar or press the Left Alt+Shift key combination to toggle between English and Chinese input.

14. To test it out, use Notepad. As you type the "hanyupinyin" of the Chinese character, a list of characters that matches it will be displayed. To select the desired character, simply press its numeric equivalent (see Figure 19).




Categories: Localization
posted by Maulik Patel at 10:00 AM | Leave Comment [0] | # Link to this entry
06/24/2008

Globalizing and Localizing Windows Applications, Part 1



With the explosive growth of the Internet and rapid globalization of the world's economies, the earth is getting smaller and smaller. The applications that you develop for a local market may soon be used in another country. If the world used a common language, that would make the life of developers much easier. However, reality is far from perfect. With globalization, you need to consider the localization of your application for each specific market segment.

When people talk about localizing their applications, they often think of simply changing the text in a window to another language. While this is part of the localization process, localization involves much more, such as:

  • Date formatting. People in the United States represent dates in a different format from someone in, say, the United Kingdom. Does "3/8/2002" represent 3rd August, 2002, or does it represent March 8th, 2002? The answer depends on where you are located.
  • Text direction. Does text read from left to right or from right to left?

As a developer, you need to be concerned with the following:

  • Globalization. When designing your application, you plan for all the necessary resources needed to enable your application to be modified with ease to suit different cultures.
  • Localization. You perform the actual transformation to ensure that the user sees the application using the culture he/she has selected.

In this first article on globalization and localization, I will explain the basics of localization and how to display localized information in your Windows application. In the next installment, I will show you how to use .NET to localize a Windows application that changes its display to suit a particular culture.

Localization Basics

A culture is a way to identify a particular setting pertinent to a location or country. You use a culture code to represent a culture. Let me give you some examples of culture codes:

  • en-US: "en" represents the English language. "en-US" provides a specific culture, that is, the culture representing English used in the US.
  • en-GB: This culture code represents the English language used in Great Britain.
  • zh-CN: This culture represents the Chinese language used in the People's Republic of China.

A neutral culture represents a culture that is associated with a language but is not specific to a particular location. For example, "en" is a neutral culture, because it represents the English language but does not provide a specific instance of where it is used.

A specific culture is a culture that is specific to a region or country. For example, "en-GB" is a specific culture.

Finally, the invariant culture is neither a neutral nor specific culture. It is English, but is not associated with any location. The invariant culture is used for representing data that is not shown to the user. For example, you use the invariant culture to persist date information to a file. This ensures that the date information would not be misrepresented if is it going to be interpreted in another specific culture.

Displaying Culture information

In .NET, you can obtain detailed information about the culture used/supported via the CultureInfo class. The following prints out all of the specific cultures supported in .NET:


Imports System.Globalization
...
Dim CI As CultureInfo
For Each CI In _
CultureInfo.GetCultures(CultureTypes.SpecificCultures)
Console.WriteLine(CI.Name)
Console.WriteLine(ControlChars.Tab & CI.DisplayName)
Console.WriteLine(ControlChars.Tab & _
CI.NumberFormat.CurrencySymbol)
Console.WriteLine(ControlChars.Tab & _
CI.DateTimeFormat.ShortDatePattern)
Next


Here are two specific ones:

...
en-US
English (United States)
$
M/d/yyyy
en-GB
English (United Kingdom)
£
dd/MM/yyyy
...


As you can see, the currency symbol for the "en-US" culture

is "$", while that of the "en-GB" culture is "£".

The date formats between the two cultures are also different, most notably in

the order in which the day and the month are displayed.




Localizing Display Information


Be default, your .NET application will automatically load the current

culture used by the operating system. However, it is often useful to

let users explicitly choose the type of culture required during runtime.


The first step towards localization is to control the way information

is formatted. For example, you want to format numbers and dates according

to a particular culture. This is accomplished through the CurrentCulture

property. As setting a culture in .NET is done at the thread level,

you can change a thread's culture by using the property:


System.Threading.Thread.CurrentThread.CurrentCulture

To illustrate how to localize display information, let's build a Windows

application. Populate the default Form1 with the following controls:



  • MainMenu

  • Label

  • TextBox

  • DateTimePicker

  • Button

  • GroupBox
The populated Windows form is as shown in Figure 1.



Figure 1. The populated Windows Form
The same goes for English in the UK and Chinese in the China cultures: When the user clicks on the US menu, switch to English in the US culture:

The MainMenu control contains three menus representing these different
cultures:


  • US
  • UK
  • China

When the DataTimePicker or TextBox (for salary) control is changed,
I will display the date and salary using the drawText() subroutine.

Private Sub DateTimePicker1_ValueChanged(ByVal sender _
As System.Object, _
ByVal e As System.EventArgs) _
Handles DateTimePicker1.ValueChanged
drawText()
End Sub

Private Sub TextBox4_TextChanged(ByVal sender As _
System.Object, ByVal e As _
System.EventArgs) Handles _
TextBox4.TextChanged
' textbox for salary
drawText()
End Sub


Basically, I use the drawText() subroutine to re-display the date of
birth and salary information. Note that for the salary, I first
assign it to a double variable and then format it using the ToString()
method with a "c" currency format string.

Sub drawText()
Try
lblDOB.Text = DateTimePicker1.Value
' assign the salary to a double
Dim salary As Double = TextBox4.Text
lblSalary.Text = salary.ToString("c")
Catch ex As Exception
lblSalary.Text = "Error!"
End Try
End Sub

Private Sub MenuItem2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MenuItem2.Click
Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
MenuItem2.Checked = True
MenuItem3.Checked = False
MenuItem4.Checked = False
drawText()
End Sub

Private Sub MenuItem3_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MenuItem3.Click
Thread.CurrentThread.CurrentCulture = New CultureInfo("en-GB")
MenuItem3.Checked = True
MenuItem2.Checked = False
MenuItem4.Checked = False
drawText()
End Sub

Private Sub MenuItem4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MenuItem4.Click
Thread.CurrentThread.CurrentCulture = New CultureInfo("zh-CN")
MenuItem4.Checked = True
MenuItem2.Checked = False
MenuItem3.Checked = False
drawText()
End Sub


When a culture is changed, I need to explicitly call the drawText()
subroutine to display the date and salary in the new format (see Figure
2):



Figure 2. Displaying the date and salary in English in the US, English in the UK, and Chinese in the China cultures.

Summary

The beauty of .NET localization is that most of the formatting issues are taken care of by the framework. However, do note that although the currency symbol changes with different cultures, the value remains unchanged. .NET only performs display localization you need to perform the actual currency conversion yourself.




Categories: Localization
posted by Maulik Patel at 10:00 AM | Leave Comment [0] | # Link to this entry
02/17/2008

How to create a Treeview Web Part



 

                                                                                                    How to create Treeview Web Part

 

  1. Open Visual studio . File --> New --> Project --> Visual C# --> Select  Web part  --> Give Proper name of file e.g. For this tutorial DocLibTreeView and click ok.
  2. Give Reference System.Drawing and system.Data files.
  3. Open DocLibTreeView.cs. Now copy the following code and paste into file nothing else to do.

using System

using System.Data

using System.Drawing

using System.ComponentModel

using System.Runtime.InteropServices

using System.Web

using System.Web.UI

using System.Web.UI.WebControls

using System.Web.UI.HtmlControls

using System.Xml.Serialization

using Microsoft.SharePoint

using Microsoft.SharePoint.Utilities

using System.Web.UI.WebControls.WebParts

using Microsoft.SharePoint.WebControls

using System.Collections.Generic

 

namespace Apoweb.WebParts

{

      [Guid("58e12124-d7ea-4ec0-bd4f-3ed6804abf9a")]

      public class DocLibTreeView : System.Web.UI.WebControls.WebParts.WebPart

      {

              private string _docName

              private string _rootImageName = "_layouts/DocLib/images/document.gif"

              private string _parentImageName = "_layouts/DocLib/images/folder.gif"

              private string _leafImageName = "_layouts/DocLib/images/file.jpg"

              private string _noExpandImageName = "_layouts/DocLib/images/dot.gif"

              private string _expandImageName = "_layouts/DocLib/images/plus.gif"

              private string _collapseImageName = "_layouts/DocLib/images/minus.gif"

              //private string _rootImageName = "LAYOUTS/DocLib/images/openfolder.jpg"

 

              TreeView docTreeView

 

              public DocLibTreeView()

              {

 

              }

              # region Properties

              [WebBrowsable(false)]             

              [Personalizable(PersonalizationScope.Shared)]             

              public string DocName

              {

                      get { return _docName }

                      set { _docName = value }

              }

              [Personalizable(PersonalizationScope.Shared)]

              [WebBrowsable(false)]

              [System.ComponentModel.Category("Settings")]               

              public string RootImageName

              {                     

                      get { return _rootImageName }

                      set { _rootImageName = value }

              }

              [Personalizable(PersonalizationScope.Shared)]

              [WebBrowsable(false)]

              [System.ComponentModel.Category("Settings")]

              public string ParentImageName

              {

                      get { return _parentImageName }

                      set { _parentImageName = value }

              }

              #endregion

              protected override void CreateChildControls()

              {

                      base.CreateChildControls()

 

                      this.Title = "Document Tree View"

 

                      docTreeView = new TreeView()

                      docTreeView.ID = "docTreeView"                      

                      docTreeView.ShowExpandCollapse.Equals(true)

                      docTreeView.ShowLines.Equals(true)

                      docTreeView.ShowCheckBoxes.Equals(true)

                      docTreeView.RootNodeStyle.ImageUrl = _rootImageName

                      docTreeView.ParentNodeStyle.ImageUrl = _parentImageName

                      docTreeView.LeafNodeStyle.ImageUrl = _leafImageName

                      docTreeView.CollapseImageUrl = _collapseImageName

                      docTreeView.ExpandImageUrl = _expandImageName

                      docTreeView.NoExpandImageUrl = _noExpandImageName

 

                      docTreeView.NodeStyle.ForeColor=Color.FromKnownColor(KnownColor.Black)

                      docTreeView.NodeStyle.Font.Name.Equals("Verdana")

                      docTreeView.NodeStyle.Font.Size=FontUnit.Parse("8")

                      docTreeView.NodeStyle.HorizontalPadding=Unit.Parse("5")                      

                      docTreeView.HoverNodeStyle.BackColor= Color.FromArgb(204,204,204)

                      docTreeView.HoverNodeStyle.BorderColor=Color.FromArgb(136,136,136)

                      docTreeView.HoverNodeStyle.BorderWidth=Unit.Parse("1")

                      docTreeView.HoverNodeStyle.BorderStyle=BorderStyle.Solid

                      docTreeView.SelectedNodeStyle.BackColor=Color.FromKnownColor(KnownColor.White)

                      docTreeView.SelectedNodeStyle.BorderColor=Color.FromArgb(136,136,136)

                      docTreeView.SelectedNodeStyle.BorderWidth=Unit.Parse("3")

                      docTreeView.SelectedNodeStyle.BorderStyle=BorderStyle.Solid

                      docTreeView.SelectedNodeStyle.ImageUrl = "/_layouts/DocLib/openfolder.jpg"

                      docTreeView.NodeIndent = 10                    

                      docTreeView.PreRender+=new EventHandler(docTreeView_PreRender)

                   

                      Controls.Add(docTreeView)

              }

                             

              public void docTreeView_PreRender(object sender, EventArgs e)

              {

                      docTreeView.Nodes.Clear()

                      BuildTreeView()                      

              }

              protected void BuildTreeView()

              {

                      SPWeb currentWeb = SPControl.GetContextWeb(Context)

                     

                      SPFolderCollection folders                      

 

                      if (this.DocName!=null)

                      {

                              folders = currentWeb.GetFolder(this.DocName).SubFolders

 

                              TreeNode rootNode = new TreeNode(folders.Folder.Name, folders.Folder.Name)

                              rootNode.SelectAction = TreeNodeSelectAction.Expand

                              rootNode.SelectAction = TreeNodeSelectAction.Select

                              rootNode.NavigateUrl = null

                              docTreeView.Nodes.Add(rootNode)

 

                              foreach (SPFolder folder in folders)

                              {

                                      if (folder.Name != "Forms")

                                      {

                                              TreeNode parentNode = new TreeNode(folder.Name, folder.Name)

                                              parentNode.SelectAction = TreeNodeSelectAction.Expand

                                              parentNode.SelectAction = TreeNodeSelectAction.Select                                              

                                              rootNode.ChildNodes.Add(parentNode)

                                              getSubFolder(parentNode, folder)

                                              //files = folder.Files

                                      }

                              }                             

                              foreach (SPFile file in folders.Folder.Files)

                              {

                                      getChildNode(rootNode, file.Name)

                              }

                      }                     

              }

              protected void getSubFolder(TreeNode parentNode, SPFolder parentFolder)

              {

                      SPFolderCollection folders = parentFolder.SubFolders

                      foreach (SPFolder folder in folders)

                      {

                              if (folder.Name != "Forms")

                              {

                                      TreeNode newNode = new TreeNode(folder.Name, folder.Name)

                                      newNode.SelectAction = TreeNodeSelectAction.Expand

                                      newNode.SelectAction = TreeNodeSelectAction.Select                                    

                                      parentNode.ChildNodes.Add(newNode)                                      

                                      getSubFolder(newNode, folder)                                      

                              }

                      }

 

                      foreach (SPFile file in folders.Folder.Files)

                      {

                              getChildNode(parentNode, file.Name)

                      }

              }

             

              public void getChildNode(TreeNode node, string fileName)

              {

                      TreeNode newNode = new TreeNode(fileName, fileName)

                                             

                      newNode.SelectAction = TreeNodeSelectAction.Select

                      newNode.SelectAction = TreeNodeSelectAction.Select

                      node.ChildNodes.Add(newNode)                      

              }

              protected override void Render(HtmlTextWriter writer)

              {                     

                      docTreeView.RenderControl(writer)

              }

 

              public override EditorPartCollection CreateEditorParts()

              {

                      List< EditorPart> editors = new List< EditorPart> ()

                      editors.Add(new DocLibTreeViewToolPart())

                      return new EditorPartCollection(editors)

              }

      }

}

  1. Now right click on project file and click on Add à New Item… à Select code file. Give name DocLibTreeViewToolPart.cs and click ok.
  2. Now copy code and paste into this file.

using System

using System.Data

using System.Drawing

using System.Diagnostics

using System.ComponentModel

using System.Runtime.InteropServices

using System.Web.UI

using System.Web.UI.WebControls

using System.Xml.Serialization

using Microsoft.SharePoint

using Microsoft.SharePoint.Utilities

using Microsoft.SharePoint.WebControls

using System.Web.UI.WebControls.WebParts

using System.Reflection

 

namespace Apoweb.WebParts

{

      class DocLibTreeViewToolPart :EditorPart

      {

              DropDownList docDropDownList

              Label selectDocLabel

              DocLibTreeView docLibTW

 

              public DocLibTreeViewToolPart()

              {

                      this.ID = "DocLibTreeViewToolPart"

                      this.Title = "Document Library Tree View"

              }

 

              protected override void CreateChildControls()

              {

                      docLibTW = WebPartToEdit as DocLibTreeView

 

                      Table editorPartTable

                      TableRow editorPartTableRow

                      TableCell editorPartTableCell

 

                      //this.Load += new EventHandler(EPCGroupMiniCalToolPart_Load)

 

                      editorPartTable = new Table()

                      editorPartTable.ID = "DocLibTreeViewEditorTable"

                      Controls.Add(editorPartTable)

 

                      editorPartTableRow = new TableRow()

                      editorPartTableCell = new TableCell()

                      editorPartTable.Rows.Add(editorPartTableRow)

                      editorPartTableRow.Cells.Add(editorPartTableCell)

 

                      selectDocLabel = new Label()

                      selectDocLabel.Text = "Select a document:"

                      selectDocLabel.Font.Bold = true

                      selectDocLabel.Font.Underline = true

                      editorPartTableCell.Controls.Add(selectDocLabel)

 

                      // add Style Override Drop Down List

                      editorPartTableRow = new TableRow()

                      editorPartTableCell = new TableCell()

                      editorPartTable.Rows.Add(editorPartTableRow)

                      editorPartTableRow.Cells.Add(editorPartTableCell)

 

                      docDropDownList = new DropDownList()

                      docDropDownList.ID = "DocDropDownList"

                      docDropDownList.Items.Clear()

 

                      SPWeb currentWeb = SPControl.GetContextWeb(Context)

                      {

                              int i = 0

                              foreach (SPList list in currentWeb.Lists)

                              {

                                      if (list.BaseType == SPBaseType.DocumentLibrary)

                                      {

                                              docDropDownList.Items.Add(new ListItem(list.Title, list.Title))

                                             

                                              i++

                                      }

                              }

                      }

                      editorPartTableCell.Controls.Add(docDropDownList)

              }

              public override bool ApplyChanges()

              {

                      try

                      {

                              EnsureChildControls()

 

                              docLibTW = WebPartToEdit as DocLibTreeView

 

                              if (docLibTW!= null)

                              {

                                      try

                                      {                                                     

                                              docLibTW.DocName= docDropDownList.SelectedValue                                                      

                                      }

                                      catch (Exception exception)

                                      {

                                              this.Zone.ErrorText = "We encountered an unexpected error.  Your changes were not applied."

                                      }

                                      return true                                      

                              }

                      }

                      catch (Exception dexp)

                      {

 

                      }

                      return false

              }

              public override void SyncChanges()

              {                   

                      EnsureChildControls()

                      docLibTW = WebPartToEdit as DocLibTreeView

                      if (docLibTW != null)

                      {

                              docLibTW.DocName = docDropDownList.SelectedValue

                      }                     

              }

      }

}

  1. Now Build and Deploy. And enjoy….

 



Categories: Share Points
posted by Maulik Patel at 10:00 AM | Leave Comment [0] | # Link to this entry
02/9/2008

How to Debug a Web Part for SharePoint 2007



The basic steps are as follows:
  1. Open the solution  with the web part(s).
  2. Now goto Project ---> Properties --> Click on Debug ---> Set Start browser with URL to your share point site url e.g. http://sharepoint:80
  3. Now Build the project. So it creates .dll and .pdb files in bin directory.
  4. Now copy those both files into C:\Inetpub\wwwroot\wss\VirtualDirectories\ ( Your website)\bin directory.
  5. Now deploy your web part project. Import the web part into the web part gallery so it is visbile, create a smaple page and add the web part to the page in design view and publish the page.
  6. Now place a break point on the code of interest in Visual Studio.
  7. Under the Debug Menu, select Attach to Process
  8. Find the w3wp.exe process.  If none exists, begin browsing to the site that has the web part you are debugging.  (I usually conduct an IIS reset so that all of the w3wp.exe processes go away and the sole one that you are interested in is easier to find)
  9. Watch as the page processes and as soon as your web part is hit, Visual Studio will load symbols and begin the debugging process
  10. Enjoy....


Categories: Share Points
posted by Maulik Patel at 10:00 AM | Leave Comment [0] | # Link to this entry
01/25/2008

Send Email From ASP.NET 2.0



Put the following code:

using System.Net
using System.Net.Mail

                MailMessage MyMail = new
                                                      MailMessage (from_email_address,to_email_address,subject,msg_body)
             
              MyMail.IsBodyHtml=true

              Now here there are two options for SMTP SERVER.
  1. If you are using GoDaddy server Then Use the following code.
                SmtpClient mysmtp = new SmtpClient ("relay-hosting.secureserver.net", 25)
 
            2. Otherwise use the following code.

                  SmtpClient mysmtp = new SmtpClient ("smtp_server_name", 25)

Then

              If your SMTP SERVER is authenticated then use following code:

                      mysmtp.Credentials = new NetworkCredential("username", "password")

          Otherwise use the following code:

                      mysmtp.UseDefaultCredentials = true            

At last

                 
mysmtp.Send(MyMail)


Cheers up.....Please put your comments.


Categories: ASP.NET
posted by Maulik Patel at 10:00 AM | Leave Comment [0] | # Link to this entry
01/16/2008

Sending Line break into Email Body From ASP



Use following for sending line break in email body.

< %
  Response.Write Replace(Request("mytextarea"), vbCrLf, "< /br> ")
%>


Categories: ASP
posted by Maulik Patel at 10:00 AM | Leave Comment [2] | # Link to this entry
01/10/2008

Send Mail From ASP ( Use this Code)



Put the following code into your function :

            set cdoMessage = Server.CreateObject("CDO.Message")
            set cdoConfig = Server.CreateObject("CDO.Configuration")
         
          cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="127.0.0.1"
          cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
          cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 
            cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2         
           
            cdoConfig.Fields.Update
            set cdoMessage.Configuration = cdoConfig
            cdoMessage.From =  fromAddr
            cdoMessage.To = recipients
            cdoMessage.Subject = subject
            cdoMessage.HtmlBody = body
            on error resume next
            cdoMessage.Send
            if Err.Number < > 0 then
                SendMail = "Email send failed: " & Err.Description & "."
            end if
            set cdoMessage = Nothing
            set cdoConfig = Nothing


Categories: ASP
posted by Maulik Patel at 10:00 AM | Leave Comment [0] | # Link to this entry
01/9/2008

Send Mail From ASP



1. First Way

< %

Const cdoSendUsingMethod = _
"http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSendUsingPort = 2
Const cdoSMTPServer = _
"http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort = _
"http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSMTPConnectionTimeout = _
"http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const cdoSMTPAuthenticate = _
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoBasic = 1
Const cdoSendUserName = _
"http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword = _
"http://schemas.microsoft.com/cdo/configuration/sendpassword"

Dim objConfig ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields ' As ADODB.Fields

' Get a handle on the config object and it's fields
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields

' Set config fields we care about
With Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "smtp_server_name"
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "username"
.Item(cdoSendPassword) = "password"

.Update
End With

Set objMessage = Server.CreateObject("CDO.Message")

Set objMessage.Configuration = objConfig

With objMessage
.To = "Display Name < email_address> "
.From = "Display Name < email_address> "
.Subject = "SMTP Relay Test"
.TextBody = "SMTP Relay Test Sent @ " & Now()
.Send
End With

Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing
%>

2. Second way:

< form method="post" action="cdosys.asp">
Email address: < input type="text" name="email_address" /> < br />
Question 1: < input type="text" name="question_1" /> < br />
Question 2: < input type="text" name="question_2" /> < br />
Question 3: < input type="text" name="question_3" /> < br />
< input name="email_subject" type="hidden" value="Subject of email" />
< input name="redirect_to" type="hidden" value="redirect_to.htm" />
< input type="reset" name="Reset" value="Reset" />
< input name="send" type="submit" value="Submit" />
< /form>

Next, copy the code below, paste it into a new page and name it cdosys.asp
< %
For Field = 1 to Request.Form.Count - 3
FieldName = Replace(Request.Form.Key(Field),"_"," ")
FieldValue = Request.Form.Item(Field)
Body = Body & FieldName & ": " & FieldValue & VbCrLf
Next

'Dimension variables
Dim objCDOSYSCon
'Create the e-mail server object
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")

'Set and update fields properties
With objCDOSYSCon
'Outgoing SMTP server
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTPSERVER"

.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

'CDO Port
.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Timeout
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

.Fields.Update

End With

'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
'Set and update email properties
With objCDOSYSMail
'0=Low, 1=Normal, 2=High

.Fields("urn:schemas:httpmail:importance").Value = 1

'Who the e-mail is from
.From = Request.Form("email_address")

'Who the e-mail is sent to
.To = "your_email_address@your-domain.co.uk"

'Who the e-mail is CC'd to
.Cc = ""
'The subject of the e-mail
.Subject = Request.Form("email_subject")
'Set the e-mail body format (HTMLBody=HTML TextBody=Plain)
.TextBody = Body
.Fields.Update
'Send the e-mail
.Send
End With
'Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
'Rederect after sending email
Response.Redirect Request.Form("redirect_to")
%>
  


Categories: ASP
posted by Maulik Patel at 10:00 AM | Leave Comment [0] | # Link to this entry


« Previous Posts | Page 1 of 9