"CITE" When Application.startuppath is not available in a Class library project (note: It is the time to read the file in the reflection!!) )

Source: Internet
Author: User

http://jcserver.blog.163.com/blog/static/24044859200851582354135/

Usually when we winform programming, to get the folder path that the program is currently running is Application.startuppath, but Application.startuppath is not available when writing the class library project, because we simply cannot use the using System.Windows.Forms, to introduce the Application.startuppath namespace, which we will use AppDomain.CurrentDomain.BaseDirectory.

private static string fullpathfilename = Application.startuppath + "//set.ini"; For WinForm
private static string fullpathfilename = appdomain.currentdomain.basedirectory+ "//set.ini"; For class projects

         Public Static voidWritelog (stringtxt) {            Try            {                stringPath = Application.startuppath +@"\log\"+ DateTime.Now.ToString ("YYYY-MM-DD") +@"\"; if(!directory.exists (path))                {directory.createdirectory (path); } Path+ = DateTime.Now.ToString ("YYYYMMDD") +"-"+ DateTime.Now.ToString ("HH") +". txt"; if(!file.exists (path))                {file.create (path);                } FileStream FS;                StreamWriter SW; FS=NewFileStream (path, filemode.append); SW=NewStreamWriter (FS, Encoding.default); Sw. Write (DateTime.Now.ToString ("HH:mm:ss") +" "+ txt +"\ r \ n"); Sw.                Close (); Fs.            Close (); }            Catch(Exception ex) {Writelog ("The program has an exception (Writelog). Details:"+Ex.            Message); }        }

"CITE" When Application.startuppath is not available in a Class library project (note: It is the time to read the file in the reflection!!) )

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.