Windows Phone 7在访问目录时崩溃 [英] Windows Phone 7 crash when accessing directory

查看:170
本文介绍了Windows Phone 7在访问目录时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过C#获取Windows Phone 7中的目录信息。我的应用程序冻结或崩溃时,我打电话:

  System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(Content /级别); 

当我尝试确定应用程序的路径时,它也冻结,所以我认为这是问题所在谎言。



我可能做错了什么,我能做些什么来解决这个问题?

更新:
看来这个问题是有关sequirity问题,但我不知道如何解决这个问题。有没有可能另一种方式来找到没有这个sequirity isue根目录?

如果它有所不同这些文件存储在XNA内容管道。

$为了在实际的xap(称为标题存储)中访问文件,首先必须将其导出为 Content 来自XNA内容管道。从内容项目中选择文件,然后在属性下设置它的 Build Action Content (我相信 None 做同样的事情)。现在,他们将直接导出到您的XAP,并可在您的游戏/应用程序中访问。

其次,要访问标题存储中的文件,您不能直接在WP7上访问根目录。使用这个课程来访问文件标题存储:

 使用(StreamReader r = 
新StreamReader(TitleContainer.OpenStream(Content / Levels / Level1 .xml)))
{
//读取文件
}

该方法返回一个 System.IO.Stream ,您可以直接使用该文件本身。



如果你的游戏需要知道一个特定文件夹中的所有文件,目录枚举等在这个平台上是不允许的,所以你必须事先在编译时生成它,这可以使用内容管道:


http:// xbox.create.msdn.com/en-US/sample/contentmanifestextensions


I am having trouble getting info on a directory in Windows Phone 7 with C#. My application freezes or crashes when I call:

System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("Content/Levels");

It also freezes when I try to determine the path of the application so I think this is where the problem lies.

What am I possibly doing wrong and what can I do to fix this?

Update: It seems this problem is related to a sequirity issue but I don't know how to resolve this. Is there possibly another way to find the root directory withouth this sequirity isue?

If it makes a differences these files are stored in the XNA content pipeline.

解决方案

To access a file within the actual xap (known as "title storage"), first of all you must export it as Content from the XNA Content Pipeline. Select the file(s) from your Content Project and under Properties set its Build Action to Content (I believe None does the same thing). Now they will export directly, raw, to your XAP and are accessible within your game/app.

Secondly, to access files from the title storage, you can't simply access the root directory directly on WP7. Use this class to access files from the title storage:

using (StreamReader r = 
new StreamReader(TitleContainer.OpenStream("Content/Levels/Level1.xml")))
{
    //read the file
}

The method returns a System.IO.Stream that you can use for direct access into the file itself.

If your game needs to know all the files within a particular folder, directory enumerating and the like is not really allowed on this platform, so you would have to generate it beforehand at compile time, which is possible using the Content Pipeline:

http://xbox.create.msdn.com/en-US/sample/contentmanifestextensions

这篇关于Windows Phone 7在访问目录时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆