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!!) )