English 中文(简体)
Windows 电话 7 独立存储器不允许使用 Windows 电话7 操作FileStream
原标题:Windows Phone 7 Operation not permitted on IsolatedStorageFileStream

我在一个有目录的应用程序上工作, 它从网络上通过 XML 将其拉入, 将其写入本地的 XML 文件, 然后从那里读取以显示联系人 。 我和我的孤立的StorageFileStream 有问题, 因为操作是不允许的 。 这是我的代码 :

IsolatedStorageFile isoStorage = IsolatedStorageFile.GetUserStoreForApplication();
        IsolatedStorageFileStream file = isoStorage.OpenFile("Components/contacts.xml", FileMode.OpenOrCreate, FileAccess.Read);
        var reader = new StreamReader(file);
        XElement appDataXml = XElement.Load(reader);
        lstContacts.ItemsSource = from contact in appDataXml.Descendants("contact")
                                  select new ContactItem
                                  {
                                      ImageSource = contact.Element("Image").Value,
                                      FName = contact.Element("FName").Value,
                                      LName = contact.Element("LName").Value,
                                      Extension = contact.Element("Extension").Value,
                                      Email = contact.Element("Email").Value,
                                      Cell = contact.Element("Cell").Value,
                                      Title = contact.Element("TitleName").Value,
                                      Dept = contact.Element("deptName").Value,
                                      Office = contact.Element("officename").Value,
                                      ID = contact.Element("ID").Value
                                  };

我可以直接从互联网上拖动它并将其放入 lst Contacts ,但我甚至无法打开文件将其写入文件( 以其下线可用的方式)。 < a href=" http:// pastebin.com/ JHQnQehQ" rel=" nofollow" > 这是我被放入一个糊式bin 的实际错误。 这直接发生在 < code> 孤立的StorageFileStream 文件 = isoStorage. OpenFile (“ commonents/ contacts.xml” 、 FileMode. OpenOrcreate、 FileAcess. Read); 。

非常感谢任何帮助。

最佳回答

我找到了问题。问题是,在我运行之前,我系统上已经创建了文件, 但它不喜欢这样。

问题回答

当您下载并保存文件时, 请确定您关闭文件, 然后再尝试读取它 。

You should wrap File The Readers/Writers in using blocks as this is a quick and safe way to do this (see MSDN Sample below) http://msdn.microsoft.com/en-us/library/aa664736(v=vs.71).aspx

using System;
using System.IO;
class Test
{
   static void Main() {
      using (TextWriter w = File.CreateText("log.txt")) {
         w.WriteLine("This is line one");
         w.WriteLine("This is line two");
      时 时
      using (TextReader r = File.OpenText("log.txt")) {
         string s;
         while ((s = r.ReadLine()) != null) {
            Console.WriteLine(s);
         时 时
      时 时
   时 时

时 时





相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签