开发者

multi lining files in IsolatedStorage @ Windows Phone 7

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


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;


You can use

StreamReader.Writeline

and

StreamRead.ReadLine

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜