wpf下导入txt文件 请问如何在wpf下导入txt文件,能给出个具体的例子吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以参考这个例子:http://www.cnblogs.com/wpf123/archive/2009/12/20/2347395.html 你是要读取TXT内容?文件流读入就好了。 private TestTemplate ReadTemplate() { StreamReader sr = null; try { sr = new StreamReader("Resources\\TestTemplate.txt"); } catch (System.Exception ex) { } if (sr == null) { return; } string strTempContent = sr.ReadToEnd(); if (!strTempContent.Equals("")) { using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(strTempContent))) { try { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(TestTemplate)); testTemplate= (TestTemplate)serializer.ReadObject(ms); } catch (System.Exception ex) { } } } sr.Close(); }//[System.Runtime.Serialization.DataContract] public class TestTemplate { [System.Runtime.Serialization.DataMember] public int Key1{ get; set; } [System.Runtime.Serialization.DataMember] public int key2{ get; set; } [System.Runtime.Serialization.DataMember] public int key3 { get; set; } [System.Runtime.Serialization.DataMember] public string KeyValue1{ get; set; } [System.Runtime.Serialization.DataMember] public string KeyValue2{ get; set; }[System.Runtime.Serialization.DataMember] public string KeyValue3{ get; set; } }//TestTemplate.txt里内容"orderPrintTemplate" : [ { "Key1" : "PRINT_TIME", "KeyValue1" : "2010-212", "Key1" : "PRINT_TIME", "KeyValue1" : "2010-212","Key1" : "PRINT_TIME", "KeyValue1" : "2010-212", }, { "Key" : "RECEIPT_TITLE", "Value" : "领收证", } ]} //TestTemplate.txt里内容"orderPrintTemplate" : [{[align=right]"Key1" : "PRINT_TIME1","KeyValue1" : "2010-212","Key2" : "PRINT_TIME1","KeyValue2" : "2010-212","Key3" : "PRINT_TIME3","KeyValue3" : "2010-212",[/align]},{[align=right]"Key1" : "PRINT_TIME1","KeyValue1" : "2010-212","Key2" : "PRINT_TIME1","KeyValue2" : "2010-212","Key3" : "PRINT_TIME3","KeyValue3" : "2010-212",[/align]} ]} 文件流读取! public string ReadText(string Path) { StreamReader sr = new StreamReader(Path, Encoding.Default); string readtxt = sr.ReadToEnd(); sr.Close(); return readtxt; } 怎样为没有解决方案的项目添加解决方案 .net 页面传递问题 很简单的一个问题,编译不过很迷惑 命名空间中显示的元素无法定义为private 帮忙打包,C#定时修改系统日期. C#如何生成软件各位解决解决 高分求救一个打印问题~~~高手请讲 请问委托主要有那些方面的用途? 哪里有分析表达式并求值的控件? 为什么只开C#版呢?不如改名为.NET版算了。 关于保存数据问题,大家给点意见 C# 水晶报表自定义内容
{
StreamReader sr = null;
try
{
sr = new StreamReader("Resources\\TestTemplate.txt");
}
catch (System.Exception ex)
{
}
if (sr == null)
{
return;
} string strTempContent = sr.ReadToEnd();
if (!strTempContent.Equals(""))
{
using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(strTempContent)))
{
try
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(TestTemplate));
testTemplate= (TestTemplate)serializer.ReadObject(ms);
}
catch (System.Exception ex)
{
}
}
}
sr.Close();
}
//
[System.Runtime.Serialization.DataContract]
public class TestTemplate
{
[System.Runtime.Serialization.DataMember]
public int Key1{ get; set; } [System.Runtime.Serialization.DataMember]
public int key2{ get; set; } [System.Runtime.Serialization.DataMember]
public int key3 { get; set; } [System.Runtime.Serialization.DataMember]
public string KeyValue1{ get; set; } [System.Runtime.Serialization.DataMember]
public string KeyValue2{ get; set; }
[System.Runtime.Serialization.DataMember]
public string KeyValue3{ get; set; }
}
//TestTemplate.txt里内容
"orderPrintTemplate" : [ {
"Key1" : "PRINT_TIME",
"KeyValue1" : "2010-212",
"Key1" : "PRINT_TIME",
"KeyValue1" : "2010-212",
"Key1" : "PRINT_TIME",
"KeyValue1" : "2010-212", },
{
"Key" : "RECEIPT_TITLE",
"Value" : "领收证",
}
]
}
"orderPrintTemplate" : [{
[align=right]"Key1" : "PRINT_TIME1",
"KeyValue1" : "2010-212",
"Key2" : "PRINT_TIME1",
"KeyValue2" : "2010-212",
"Key3" : "PRINT_TIME3",
"KeyValue3" : "2010-212",[/align]},
{
[align=right]"Key1" : "PRINT_TIME1",
"KeyValue1" : "2010-212",
"Key2" : "PRINT_TIME1",
"KeyValue2" : "2010-212",
"Key3" : "PRINT_TIME3",
"KeyValue3" : "2010-212",[/align]}
]
}
public string ReadText(string Path)
{
StreamReader sr = new StreamReader(Path, Encoding.Default);
string readtxt = sr.ReadToEnd();
sr.Close();
return readtxt;
}