Asp.net some cool and practical. Net Skills page 1/2

Source: Internet
Author: User

I.. NET Framework

1. How to obtain the system folder

Use the getfolderpath method of the system. enviment class. For example:

Environment. getfolderpath (environment. specialfolder. Personal)

2. How to obtain the path of the EXE file being executed

1) Use the executablepath attribute of the application class

2) system. reflection. Assembly. getexecutingassembly (). Location

3. How to check the operating system version

Use the osversion attribute of enviment, for example:

Operatingsystem OS = environment. osversion;

MessageBox. Show (OS. version. tostring ());

MessageBox. Show (OS. Platform. tostring ());

4. How to obtain the file name part based on the complete file name,

Use the system. Io. Path class method getfilename or getfilenamewithoutextension

5. How to get the file extension by the full name of the file

Use System. Io. Path. getextension static method

6. What is the difference between the syntax of VB and C # click here

7. How to obtain the User Name of the current computer, whether the computer is connected to the Internet, how many monitors, the domain, and the mouse keys

Use the static attributes of the system. Windows. Forms. systeminformation class

8. What is the role of modifying the [stathread] feature of the main method?

CurrentProgramRun in single thread mode

9. How to read the contents of a CSV file

You can use odbcconnection to create a link to the CSV file. The format of the link string is: "driver = {Microsoft text Driver (*. txt ;*. CSV)}; DBQ = "+ CVS file folder path +" extensions = ASC, CSV, tab, txt; persist Security info = false ";

After creating a connection, you can use dataadapter to access CSV files.

For more information, see

10. How to obtain disk overhead information,CodeThe snippet is as follows. It mainly calls the getdiskfreespaceex external method in kernel32.dll.

Public sealed class driveinfo
{
[Dllimport ("kernel32.dll", entrypoint = "getdiskfreespaceexa")]
Private Static extern long getdiskfreespaceex (string lpdirectoryname,
Out long lpfreebytesavailabletocaller,
Out long lptotalnumberofbytes,
Out long lptotalnumberoffreebytes );

Public static long getinfo (string drive, out long available, out long total, out long free)
{
Return getdiskfreespaceex (drive, out available, out total, out free );
}

Public static driveinfosystem getinfo (string drive)
{
Long result, available, total, free;
Result = getdiskfreespaceex (drive, out available, out total, out free );
Return new driveinfosystem (drive, result, available, total, free );
}
}

Public struct driveinfosystem
{
Public readonly string drive;
Public readonly long result;
Public readonly long available;
Public readonly long total;
Public readonly long free;

Public driveinfosystem (string drive, long result, long available, long total, long free)
{
This. Drive = drive;
This. Result = result;
This. Available = available;
This. Total = total;
This. Free = free;
}
}

You can use

Driveinfosystem info = driveinfo. getinfo ("C :");

11. How to obtain the index location of case-insensitive substring

1) convert the two strings to lowercase and use the indexof method of the string:

String strparent = "The codeproject site is very informative .";

String strchild = "codeproject ";

// The line below will return-1 when expected is 4.
Int I = strparent. indexof (strchild );

// The line below will return proper index
Int J = strparent. tolower (). indexof (strchild. tolower ());

2)

A more elegant method is to use the indexof method of the compareinfo class under the system. Globalization namespace:

Using system. Globalization;

String strparent = "The codeproject site is very informative .";

String strchild = "codeproject ";
// We create a object of compareinfo class for a neutral culture or a culture insensitive object
Compareinfo compare = cultureinfo. invariantculture. compareinfo;

Int I = compare. indexof (strparent, strchild, compareoptions. ignorecase );

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.