【CITE】当类库项目中无法使用Application.StartupPath的时侯 (注:主要是在进行反射读取文件的时候!!)
http://jcserver.blog.163.com/blog/static/24044859200851582354135/
通常我们WinForm编程时,要获取程序当 前运行的文件夹路径会用Application.StartupPath ,但是Application.StartupPath在编写类库项目时却无法 使用,因为我们根本无法用using System.Windows.Forms;来引入Application.StartupPath 的命名空间,这个时侯我们要用AppDomain.CurrentDomain.BaseDirectory。
private static string fullPathFileName = Application.StartupPath + "//Set.Ini "; //用于WINFORM
private static string fullPathFileName = AppDomain.CurrentDomain.BaseDirectory+"//Set.Ini";//用于类项目
public static void WriteLog(string txt)
{ try
{ string path = 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 = new FileStream(path, FileMode.Append); sw = new StreamWriter(fs, Encoding.Default); sw.Write(DateTime.Now.ToString("HH:mm:ss") + " " + txt + "\r\n"); sw.Close(); fs.Close(); } catch (Exception ex)
{ WriteLog("程序发生异常(WriteLog)。详情:" + ex.Message); } }
【CITE】当类库项目中无法使用Application.StartupPath的时侯 (注:主要是在进行反射读取文件的时候!!)的更多相关文章
- 当类库项目中无法使用Application.StartupPath
通常我们WinForm编程时,要获取程序当前运行的文件夹路径会用Application.StartupPath ,但是Application.StartupPath在编写类库项目时却无法使用,因为我们 ...
- .NET Core 3.0或3.1 类库项目中引用 Microsoft.AspNetCore.App
本文为原创文章.首发:http://www.zyiz.net/ 在 ASP.NET Core 3.0+ web 项目中已经不需要在 .csproj 中添加对 Microsoft.AspNetCore. ...
- 在 VS 类库项目中 Add Service References 和 Add Web References 的区别
原文:在 VS 类库项目中 Add Service References 和 Add Web References 的区别 出身问题: 1.在vs2005时代,Add Web Reference(添加 ...
- 在类库项目中使用log4net(RollingFileAppender)记录日志
1.创建解决方案 2.创建类库项目 3.根据需要修改命名空间,修改(和/或)添加类到类库 4.引用log4net 5.类库项目根目录下创建leg4net配置文件,如D3CallTriggerPlugi ...
- 在普通的"类库"项目中添加 WPF 的 Window 对象
最近开发一个 WPF 项目, 在此项目中有个类库工程, 在开发的过程中发现在类库工程中竟然添加不了 WPF 窗口对象和一些其他的 WPF 对象,在新建窗口中选 WPF 类型,只有一个 “用户控件(WP ...
- JavaWeb项目中获取对Oracle操作时抛出的异常错误码
最近在项目中碰到了这么一个需求,一个JavaWeb项目,数据库用的是Oracle.业务上有一个对一张表的操作功能,当时设置了两个字段联合的唯一约束.由于前断没有对重复字段的校验,需要在插入时如果碰到唯 ...
- WPF 添加 Resources Dictionary 资源 一般类库项目中无法添加资源文件(ResourceDictionary)
在文件夹或者项目右键-> Add(添加),会弹出可以快捷添加的资源,但是你会发现没有 ResourceDictionary资源可以选择. 解决此问题方法: 第一步:工程->右键->U ...
- .NET Core类库项目中如何读取appsettings.json中的配置
这是一位朋友问我的问题,写篇随笔回答一下.有2种方法,一种叫丑陋的方法 —— IConfiguration ,一种叫优雅的方法 —— IOptions . 1)先看丑陋的方法 比如在 RedisCli ...
- abp项目中无法使用HttpContext.Current.Session[""]的问题
web项目Global.asax.cs中加入如下代码 public override void Init() { this.PostAuthenticateRequest += (sender, e) ...
随机推荐
- c#存储过程
1. 只返回单一记录集的存储过程 SqlConnection sqlconn = new SqlConnection(conn); SqlCommand cmd = new SqlCo ...
- 使用MSCOMM发送任意文件,还有一些注意事项
第一步:发送文件 FILE* pSENDFILE = _wfopen(m_edit_chosefile, _T("rb"));//以二进制打开待发送文件的的文件指针 fseek(p ...
- SGU 105 div.3 找规律
There is sequence 1, 12, 123, 1234, ..., 12345678910, ... . Given first N elements of that sequence. ...
- Eclipse如何生成jar包
Eclipse如何生成jar包 图1 右击项目Properites,选择Android,选择Is Library,然后会编译生成jar包在bin目录下.
- Python存取XML方法简介
<?xml version="1.0" encoding="utf-8"?> <Schools> <School Name=&qu ...
- CodeForces 478C Table Decorations
Table Decorations Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u ...
- jquery ajax请求时,设置请求头信息
设置一个名为 headers 的参数 参考代码: // attempt to make an XMLHttpRequest to indeed.com // jQuery 1.6.1 and Chro ...
- Shifting List Item Values From One List To Another In Oracle Forms
Suppose you have two T-List items in form and you want to shift element values from one list to ano ...
- getting started with building a ROS simulation platform for Deep Reinforcement Learning
Apparently, this ongoing work is to make a preparation for futural research on Deep Reinforcement Le ...
- 关于dom ready事件
0.加载完页面,解析完所有标签(不包括执行CSS和JS),并如规范中所说的设置 interactive 和执行每个静态的script标签中的JS,然后触发. 1.没有js,有css,有img,DOMC ...