windows-phone-7 – 在phone7中打开一个项目文件
发布时间:2020-12-14 04:02:14 所属栏目:Windows 来源:网络整理
导读:你好, 我在VisualStudio中有一个项目,它在根节点下面包含一个文件夹’xmlfiles’.这个文件夹包含一个文件’mensen.xml’,我尝试打开它… 但是,当我尝试打开该文件时,调试器会介入并抛出异常. 我试过了 ????????????if(File.Exists(@“/ xmlfiles / mensen.xm
你好,
我在VisualStudio中有一个项目,它在根节点下面包含一个文件夹’xmlfiles’.这个文件夹包含一个文件’mensen.xml’,我尝试打开它… 但是,当我尝试打开该文件时,调试器会介入并抛出异常. 我试过了 ????????????if(File.Exists(@“/ xmlfiles / mensen.xml”)) FileStream fs = File.Open("/xmlfiles/mensen.xml",FileMode.Open); TextReader textReader = new StreamReader(fs); kantinen = (meineKantinen)deserializer.Deserialize(textReader); textReader.Close(); Nothin正在工作:(. 解决方法
如果您只是打开它来阅读它,那么您可以执行以下操作(假设您已将文件的构建操作设置为资源):
System.IO.Stream myFileStream = Application.GetResourceStream(new Uri(@"/YOURASSEMBLY;component/xmlfiles/mensen.xml",UriKind.Relative)).Stream; 如果您尝试读取/写入此文件,则需要将其复制到隔离存储. (务必使用System.IO.IsolatedStorage添加) 您可以使用以下方法: private void CopyFromContentToStorage(String fileName) { IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication(); System.IO.Stream src = Application.GetResourceStream(new Uri(@"/YOURASSEMBLY;component/" + fileName,UriKind.Relative)).Stream; IsolatedStorageFileStream dest = new IsolatedStorageFileStream(fileName,System.IO.FileMode.OpenOrCreate,System.IO.FileAccess.Write,store); src.Position = 0; CopyStream(src,dest); dest.Flush(); dest.Close(); src.Close(); dest.Dispose(); } private static void CopyStream(System.IO.Stream input,IsolatedStorageFileStream output) { byte[] buffer = new byte[32768]; long TempPos = input.Position; int readCount; do { readCount = input.Read(buffer,buffer.Length); if (readCount > 0) { output.Write(buffer,readCount); } } while (readCount > 0); input.Position = TempPos; } 在这两种情况下,请确保将文件设置为“资源”,然后使用程序集的名称替换YOURASSEMBLY部分. 使用上述方法,访问您的文件只需执行以下操作: IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication(); if (!store.FileExists(fileName)) { CopyFromContentToStorage(fileName); } store.OpenFile(fileName,System.IO.FileMode.Append); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
推荐文章
站长推荐
- windows-phone-7 – 在Windows Phone中购买应用程
- 如何优雅地停止正在侦听Windows上的管道的服务器
- microsoft-graph – 如何在特定时间段内获取micr
- windows-server-2008-r2 – 如何在Windows Serve
- 使用rem适配不同屏幕的移动设备
- windows – 从光学介质中恢复,忽略读取错误
- x86_64:为什么uint_least16_t比uint_fast16_t快
- windows-8 – 尽管代码正确,Windows 8 Metro Til
- 在Windows上进行Qt DLL部署
- win2003 IIS6+PHP5+MySQL5+Zend Optimizer+phpMy
热点阅读