获取运行时的动态目录

private static string GetDataDir_Data()
{
var parent = Directory.GetParent(Directory.GetCurrentDirectory()).Parent;
string startDirectory = null;
if (parent != null)
{
var directoryInfo = parent.Parent;
if (directoryInfo != null)
{
startDirectory = directoryInfo.FullName;
}
}
else
{
startDirectory = parent.FullName;
}
return Path.Combine(startDirectory, "Data\\");
}

//参考之Aspose.Words-for-.NET-master

//其他

string d2 = AppDomain.CurrentDomain.BaseDirectory;

I/O操作之文件,目录删除

public void CleanTempPath(TCPRptParamInfo param)
{
string TempPath = ConfigHelper.ReadConfig("TempPath");
string returnStr = TempPath + "\\" + param.SubTempDirectory + "\\"; if (Directory.Exists(returnStr))
{
FileInfo[] fi = new DirectoryInfo(returnStr).GetFiles();
int fileLenght = fi.Length;
for (int i = ; i < fileLenght; i++)
{
fi[i].Delete();
}
//Directory.Delete(returnStr); //删目录,非空目录不能直接删除
}
}
if (Directory.Exists(returnStr))
{
Directory.Delete(returnStr,true);//直接删除非空目录
}

读文本方式之一

string dataDir = AppDomain.CurrentDomain.BaseDirectory; //Get Current Directory

StreamReader srPerson = File.OpenText(FaleName1);//文本文件完整路径
StreamReader strData = File.OpenText(dataDir + "data.txt");
while (!strData.EndOfStream)
{
string textLine = srPerson.ReadLine();
//TODO
}

读文本方式之二

using System.IO;

string dataPath = GetMaterialPath(param, DocType.LeaderAttribute) + "data.txt";
string configstr = System.IO.File.ReadAllText(dataPath, Encoding.Default); //核心方法:读文本方式之一
Dictionary<string, string> allConfig = ConfigHelper.ParseConfigString(configstr); public static class ConfigHelper
{
public static string ReadConfig(string key)
{
return System.Configuration.ConfigurationManager.AppSettings[key];
} public static Dictionary<string, string> ParseConfigString(string config)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
string[] array = config.Split(new char[]
{
'■'//行结束标记
});
string[] array2 = array;
for (int i = ; i < array2.Length; i++)
{
string text = array2[i];
string[] array3 = text.Split(new char[]
{
':'
});
if (array3.Length == )
{
dictionary.Add(array3[].Trim(), array3[].Trim());
}
else
{
dictionary.Add(text.Trim(), null);
}
}
return dictionary;
}
}

随机推荐

  1. 【WPF】Combobox指定选中值用selectedValue不是很灵的时候,

    wpf combobox 指定选中的值,前题,combobox是通过数据库绑定的ItemsSource:所以再指定的时候用selectValue不是很成功!我的解决方法是 生成一个字典,办值和索引对应 ...

  2. hql中in关键字的用法

    hql: from " + FoodComment.class.getName() + " f where f.id in :groupIds" 封装的方法: publi ...

  3. css 的一些基本操作

    日常基本使用的一些操作,持续完善中: 设置按钮圆角:border-radius:5px; 设置高度:height: 30px; 设置宽度:width: 64px; 使用span标签内容过长自动换行解决 ...

  4. Xtrabackup原理及使用innobackupex进行MySQL数据库备份恢复

    Xtrabackup是由percona提供的mysql数据库备份工具,据官方介绍,这也是世界上惟一一款开源的能够对innodb和xtradb数据库进行热备的工具. Xtrabackup中主要包含两个工 ...

  5. java 中正则表达式匹配

    String str = "#a#,#b#"; String reg="\\#+[^\\#]+\\#+"; Pattern p=Pattern.compile( ...

  6. CUDA[2] Hello,World

    Section 0:Hello,World 这次我们亲自尝试一下如何用粗(CU)大(DA)写程序 CUDA最新版本是7.5,然而即使是最新版本也不兼容VS2015 ...推荐使用VS2012 进入VS ...

  7. php 使用函数中遇到的坑之----strpos

    strpos — 查找字符串首次出现的位置 mixed strpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) <?ph ...

  8. CodeForces 698C LRU

    吐槽一句:这数据造得真强-. 题意:有一个大小为k的缓存区,每次从n种物品中按照一定的概率选取一种物品尝试放进去.同一个物品每一次选取的概率都是相同的.如果这种物品已经放进去过就不再放进去.如果缓存区 ...

  9. 发送ajax请求时页面被刷新

    浏览器默认会认为 button 的属性是submit.type='submit',会发生提交表单的默认行为,为button添加type="button"即可.

  10. 关于SQL的相关笔记【长期更新,只发一帖】

    场景[1]多表联查时,主表与关联表同时与同一张(第三张表)有关联,类似三角恋关系- - 涉及表: HOUSE:记录了房屋信息 ROOMS:记录了房间信息 HOUSE_STATUS:记录了状态信息的中文 ...