我的代码是:
private string _filename = System.Reflection.Assembly.GetExecutingAssembly().Location
+ "\\" + System.Windows.Forms.Application.ProductName + ".log";
string ret = _filename;
int index = ret.LastIndexOf(".");
try
{
if (index > 0)
{
ret = ret.Substring(0, index);
}
ret = ret + "Zipped.zip";
ZipFile.CreateFromDirectory(filename, ret);
这最后一行给了我一个System.IOException。它说目录名称无效。为什么_filename是无效的目录名?
答案 0 :(得分:0)
System.Reflection.Assembly.GetExecutingAssembly()。位置返回一个完整的位置(包括文件),你将另一个文件追加到最后:
示例:C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Temporary ASP.NET Files \ webapps_testsite \ 0f5c8994 \ d5e42433 \ App_Web_ir4asgqi.dll \ ProductName.log
尝试使用_filename:
private string _filename = System.Reflection.Assembly.GetExecutingAssembly().Location.Substring(0,System.Reflection.Assembly.GetExecutingAssembly().Location.LastIndexOf("\\")) + "\\" + System.Windows.Forms.Application.ProductName + ".log";