获取运行时的动态目录

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. 资源描述结构(Resource Description Framework,RDF)

    资源描述框架(Resource Description Framework),一种用于描述Web资源的标记语言.RDF是一个处理元数据的XML(标准通用标记语言的子集)应用,所谓元数据,就是" ...

  2. python优先队列,队列和栈

    打印列表的疑问 class Node: def __str__(self): return "haha" print([Node(),Node()]) print(Node()) ...

  3. 【MySQL】mysql 1449 : The user specified as a definer ('root'@'%') does not exist

    权限问题,授权 给 root  所有sql 权限 1.mysql> grant all privileges on *.* to root@"%" identified by ...

  4. Java中List循环遍历的时候删除当前对象(自己)

    方法一 Java代码   ArrayList<String> list = new ArrayList<String>();           list.add(" ...

  5. mysql Packet for query is too large (1185 > 1024)异常

    注:最近mysql一直提示如下错误 Packet for query is too large (1185 > 1024). You can change this value on the s ...

  6. 并发包的线程池第二篇--Executors的构造

    上一篇讲述了ThreadPoolExecutor的执行过程,我们也能看出来一个很明显的问题:这个线程池的构造函数比较复杂,对于不十分理解其运作原理的程序员,自己构造它可能体现和想象中不一样的行为.比如 ...

  7. C#执行Dos命令公用方法

    private static string InvokeCmd(string cmdArgs) { string Tstr = ""; Process p = new Proces ...

  8. CSS之列表标签

    1 无序列表 无序列表,用来表示一个列表的语义,并且每个项目和每个项目之间,是不分先后的. ul就是英语unordered list,"无序列表"的意思. li 就是英语list ...

  9. 深夜用git真是醉了

    t吐槽一下那些 感觉命令行高效的傻逼们 我只想吃个牛肉串  你让我先学会宰牛? 命令不是对底层代码的封装? 程序的终极奥义就是把很多复杂的东西,封装到一个按钮就能完成 .叫做简为美. 浪费别人的时间等 ...

  10. 数学规划模型的matlab求解 非线性最小二乘lsqnonlin

    LINK :http://blog.sina.com.cn/s/blog_49f037d60100ok8y.html