C # block module ABC (4)

Source: Internet
Author: User
Tags dsn mailmessage

13. How do I send emails in C?

To implement the mail sending function in C #, the required tool is Visual C #.. NET. The namespace involved is System. web. util, the collection has System. web. dll.

Specifically, we can use the SmtpMail class to send emails in the C # application. By default, emails are queued in the system to ensure that the calling program does not cause network congestion. The SmtpMail class is defined in the System. Web. Util namespace. Before using SmtpMail, you must call

Using System. Web. Util

This class only has one member function Send. It is responsible for sending an email message. Either a MailMessage class or four parameter variables can be passed to the Send function. The Send function can be called in two forms:

SmtpMail. Send (txtFrom. Text, txw.text, txtSubject. Text, txtMessage. Text );

Or (if you do not want to call System. Web. Util ):

System. Web. Util. Smptmail. Send (fromString, toString, SubjeOfTheMailString, MessageOfTheMailString );

We can call the Send method in two ways:

1. Pass MailMessage as a parameter:

Public static void Send (MailMessage );

Here, MailMessage is a class.

MailMessage mailMsg = new MailMessage ();

MailMsg. From ="From@fromServer.com";

MailMsg. To ="To@toServer.com";

MailMsg. Cc ="Cc@ccServer.com "";

MailMsg. Bcc ="Bcc@bccServer.com";

MailMsg. Subject = "SubjectOfTheMailString ";

MailMsg. Body = "BodyOfTheMailString ";

SmtpMail. Send (mailMsg );

2. Direct Method

Public static void Send (string from, string to, string subject, string messageText );

From = sender's Email information, to = recipient's Email information, subject = Email subject, messageText = Email information subject.

For example:

SmtpMail. Send ("mcb@mindcracker.com ","Webmaster@mindcracker.com", "Subject", "Message body ");

The following explains how to obtain an input value from the console. If C ++ is used, cin and cout are functions read and written to the console.

Enter the code in the text editor and save it as read. cs:

Using System;

Class ReadStr

{

Public static void Main ()

{

Console. Write ("Enter your name :");

String szName = Console. ReadLine ();

Console. WriteLine ("Hey" + szName );

}

}

Compile it on the command line in the format of cs read.cs. this creates an exefile read.exe, which is in the same directory as the read. cs file. Finally, run this exe.


 

14. How do I read Windows registry information?

Before introducing how to read registry information, explain how to add registration entries.

1. Add registry data

The following text shows the actual registration information. Copy and paste the content to a text file, save the file with the extension. reg, and double-click the file to input the Registry content.

/* Windows Registry Editor Version 5.00

[HKEY_CURRENT_USERSoftwareTAWBSE]

"DSN" = "TAWReports"

"User" = "TAW1"

"Password" = "taw1.1"

"Server" = "dbserver"

"IP" = ""

*/

2. Read registration data

2.1 create two RegistryKey variables.

2.2 create a class containing the od object. The first parameter is HKEY (primary root keyword name), and the second parameter is "", indicating the local machine.

2.3 create subkeywords where you want to read the information.

2.4 use the Getvalue method of the RegistryKey class to read the data of the keyword information of a specific node. Here, DSN, Server, and Password are nodes.

The following code reads the registration data just added to the registry:

Namespace CONAPP

{

Using System;

Using Microsoft. Win32;

Public class Class1

{

Public Class1 ()

{

//

// TODO: Add Constructor Logic here

//

}

Public static int Main (string [] args)

{

RegistryKey SUBKEY;

RegistryKey TAWKAY = RegistryKey. OpenRemoteBaseKey (Microsoft. Win32.RegistryHive. CurrentUser ,"");

String subkey = "Software \ TAW \ BSE ";

SUBKEY = TAWKAY. OpenSubKey (subkey );

Object dsn = SUBKEY. GetValue ("DSN ");

Object user = SUBKEY. GetValue ("user ");

Object password = SUBKEY. GetValue ("password ");

Object server = SUBKEY. GetValue ("server ");

Return 0;

}

}

}

Here is the downloadable code package:Http://www.mindcracker.com/csharp/1/read_reg.cs


 

15. Use the system clipboard

The collection involved here is System. Winforms. dll, And the namespace is System. Winforms.

The system clipboard is a buffer space that provides the cut and paste functions. In C #, the ClipBoard class provides a method to place data on the system ClipBoard and restore data from the system ClipBoard. If you have used ClipBoard in C ++, you should remember IDataObject, which provides the ClipBoard data format. In. NET, you can use the DataFormat class, which executes IdataObject and provides a format-independent structure for data transmission. For more information, see DataFormat reference.

The Clipboard class has only three members, including the Clipboard constructor, GetDataObject, and SetDataObject.

16. Clipboard Constructor

The Clipboad class is derived directly from the Object class. We can directly call the Clipboard class in the application, or use the Clipboard constructor to create a Clipboard instance:

Clipboard = new Clipboard ();

You can even directly call Clipboard in the application:

IDataObject iData = System. WinForms. Clipboard. GetDataObject ();

SetDataObject Method

We can call the SetDataObject method to copy or cut data on the clipboard. The SetDataObject method has two definitions:

Public static void SetDataObject (Object );

This method uses an Object-type parameter, which can be any data, for example:

String str = "Mahesh writing data to the Clipboard ";

SetDataObject (str );

With this method, you can put any type of data on the clipboard.

The other method accepts two parameters:

Public static void SetDataObject (Object data, bool copy );

Copy indicates whether data should be stored on the clipboard after the application exits.

String str = "Mahesh writing data to the Clipboard using Copy bool ";

SetDataObject (str, true );

GetDataObject Method

The GetDataObject method restores the current data from the clipboard and returns the IdataObject:

Public static IDataObject GetDataObject ();

For example:

IDataObject dtObj = Clipboard. GetDataObject ();

Now you can call GetFormats of IDataObject to find the data format on the clipboard, for example:

Private void CutCopyData ()

{

Clipboard. SetDataObject (textBox1.SelectedText );

}

Private void PasteData ()

{

IDataObject iData = Clipboard. GetDataObject ();

File: // DetermineWhether the data is in a format you can use.

If (iData. GetDataPresent (DataFormats. Text ))

{

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.