0

I have to develop application for mobile device, using Visual Studio 2008. Application have to read files and write to them.

Problem I have that I don't know where are files when I run application on mobile device or even on device emulator in VS. If I run application on PC, everything works well.

Can you give me some point what to do and where to look at?

Thank you in advance!

I didn't mention, it's for Windows Mobile 6.5

P.S. tried to work with StringBuilder like:

StringBuilder sb = new StringBuilder();
using (StreamReader sr = new StreamReader("TestFile.txt")) 
{
    String line;
    // Read and display lines from the file until the end of 
    // the file is reached.
    while ((line = sr.ReadLine()) != null) 
    {
        sb.AppendLine(line);
    }
}
string allines = sb.ToString();
4

1 回答 1

2

手机应用程序,出于安全原因,应用了沙盒的概念,这意味着您的应用程序无权访问系统上的任何文件,如果您想使用沙盒区域来操作文件或其他类型的数据,您需要使用他们的 API 来访问它。

在 Windows Phone 7 世界中,这被称为IsolateStorage

这是一个关于如何将它与文件一起使用的好例子。


糟糕的是,我没有阅读标签windows-mobile-6.5,但我会让我的 WP7 在上面回答并在下面回答你:

Windows Mobile 没有驱动器,因此您不能使用驱动器号,并且对于该位置,这通常是您的应用程序位置的根目录(您可以从资源管理器中找到它),但通常这是我们所做的:

string path = "\\test.txt";//file Loc: *start->file explorer->text.txt*
if (!File.Exists(path))
{
    using (StreamWriter sw = File.CreateText(path))
    {
        sw.WriteLine("Hello");
        sw.WriteLine("And");
        sw.WriteLine("Welcome");
    }
}
using (StreamReader sr = File.OpenText(path))
{
    string s = "";
    label1.Text = "";
    while ((s = sr.ReadLine()) != null)
    {
        label1.Text += s;
    }
}

试试看……

于 2012-05-31T07:46:12.533 回答