isolatedStorage @ Windows Phone 7 中的多层文件

发布于 2024-10-11 07:28:12 字数 1700 浏览 2 评论 0原文

我在 IO 中创建了一些文件 在“汽车”文件中,我想添加一些其他参考信息,例如型号、颜色等...... 所以我的问题是:IO 中是否可以有多层文件 如果是,我怎样才能将它们放入流阅读器中 // 我想在文件中存储许多参数,并使用streamreader

protected override再次找到它们 void OnNavieratedTo(System.Windows.Navigation.NavigationEventArgs e) {

            //reception des parametres de la listbox
            base.OnNavigatedTo(e);
            string parameter = this.NavigationContext.QueryString["parameter"];
            this.tbTitre.Text = parameter;
            try
            {
                //Create a new StreamReader
                StreamReader editionDevisReader = null;
                IsolatedStorageFile probyOrange = IsolatedStorageFile.GetUserStoreForApplication();
                //Read the file from the specified location.
                editionDevisReader = new StreamReader(new IsolatedStorageFileStream("devis\\"+parameter+".txt", FileMode.Open, probyOrange));
                //Read the contents of the file .
                string textFile = editionDevisReader.ReadLine();

                //Write the contents of the file to the TextBlock on the page.
                tbTitre.Text = textFile;

                while (editionDevisReader != null)
                {
                    RowDefinition rowdefinition = new RowDefinition();

                    TextBlock textblock = new TextBlock();
                    textblock.HorizontalAlignment = new System.Drawing.Size(48, 20); 

                }
                editionDevisReader.Close();
            }
            catch
            {
                //If  the file hasn't been created yet.
                tbTitre.Text = "veuillez d abord creer le fichier";
            }

非常感谢

i have created some files in the IO
in the "car" files, i would like to put some other reference like model, color etc...
so my question is : is it possible to have a multi-lining files in the IO
if yes how can i get them in the streamreader
// i want to storage many parameters in a file and find them again with the streamreader

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{

            //reception des parametres de la listbox
            base.OnNavigatedTo(e);
            string parameter = this.NavigationContext.QueryString["parameter"];
            this.tbTitre.Text = parameter;
            try
            {
                //Create a new StreamReader
                StreamReader editionDevisReader = null;
                IsolatedStorageFile probyOrange = IsolatedStorageFile.GetUserStoreForApplication();
                //Read the file from the specified location.
                editionDevisReader = new StreamReader(new IsolatedStorageFileStream("devis\\"+parameter+".txt", FileMode.Open, probyOrange));
                //Read the contents of the file .
                string textFile = editionDevisReader.ReadLine();

                //Write the contents of the file to the TextBlock on the page.
                tbTitre.Text = textFile;

                while (editionDevisReader != null)
                {
                    RowDefinition rowdefinition = new RowDefinition();

                    TextBlock textblock = new TextBlock();
                    textblock.HorizontalAlignment = new System.Drawing.Size(48, 20); 

                }
                editionDevisReader.Close();
            }
            catch
            {
                //If  the file hasn't been created yet.
                tbTitre.Text = "veuillez d abord creer le fichier";
            }

thx a lot all

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼前雾蒙蒙 2024-10-18 07:28:12

是的,您可以将任何内容(最多)保存在文件中:

using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
    using (var isfs = new IsolatedStorageFileStream("myfile.txt", FileMode.OpenOrCreate, store))
    {
        using (var sw = new StreamWriter(isfs))
        {
            sw.Write("anything really. Here it's just a string but could be a serialized object, etc.");
            sw.Close();
        }
    }
}

然后您可以使用以下命令读取该文件:

var result = string.Empty;

try
{
    using (var store = IsolatedStorageFile.GetUserStoreForApplication())
    {
        if (!store.FileExists("myfile.txt"))
        {
            return result;
        }

        using (var isfs = new IsolatedStorageFileStream("myfile.txt", FileMode.Open, store))
        {
            using (var sr = new StreamReader(isfs))
            {
                string lineOfData;

                while ((lineOfData = sr.ReadLine()) != null)
                {
                    result += lineOfData;
                }
            }
        }
    }
}
catch (IsolatedStorageException)
{
    result = string.Empty; // may have partial data/file before error
}

return result;

Yes, you can save anything (up to a point) in a file:

using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
    using (var isfs = new IsolatedStorageFileStream("myfile.txt", FileMode.OpenOrCreate, store))
    {
        using (var sw = new StreamWriter(isfs))
        {
            sw.Write("anything really. Here it's just a string but could be a serialized object, etc.");
            sw.Close();
        }
    }
}

You can then read the file with:

var result = string.Empty;

try
{
    using (var store = IsolatedStorageFile.GetUserStoreForApplication())
    {
        if (!store.FileExists("myfile.txt"))
        {
            return result;
        }

        using (var isfs = new IsolatedStorageFileStream("myfile.txt", FileMode.Open, store))
        {
            using (var sr = new StreamReader(isfs))
            {
                string lineOfData;

                while ((lineOfData = sr.ReadLine()) != null)
                {
                    result += lineOfData;
                }
            }
        }
    }
}
catch (IsolatedStorageException)
{
    result = string.Empty; // may have partial data/file before error
}

return result;
四叶草在未来唯美盛开 2024-10-18 07:28:12

您可以使用

StreamReader.Writeline

StreamRead.ReadLine

来写入和读取由换行符分隔的文本块。

You can use

StreamReader.Writeline

and

StreamRead.ReadLine

to write and read blocks of text seperated by line feeds.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文