Silverlight:从XAP中读取文件
时间:2010-12-30 来源:Alan.Mo
3步骤实现从XAP中读取文件。
1)将文件加入到Silverlight项目中,并且将文件的Build Action设置为”Resuource”
2)使用如下的代码,创建URI指向文件,并且从URI中建立StreamResourceInfo
Uri uri = new Uri("SilverlightApplication6;component/MyFile.txt", UriKind.Relative)
StreamResourceInfo streamInfo = Application.GetResourceStream(uri);
其中SilverlightApplication6是silverlight程序的namespace,MyFile.txt是我们增加到Silverlight工程中的文件
3)从StreamResourceInfo中读取想关的Stream,然后使用StreamReader
if (null != streamInfo)
{
Stream stream = streamInfo.Stream;
StreamReader sr = new StreamReader(stream);
string line = String.Empty;
while ((line = sr.ReadLine()) != null)
{
}
}
相关阅读 更多 +
排行榜 更多 +