Win8 do not open and save the file through a new open window, click to display the text content, click to save the file

Source: Internet
Author: User

One of the previous blogs talked about opening and saving files by opening a new window, which focuses on how to one step to open and save files (also in the case of a. txt text file).


We want to open the. txt text file, just want the text content inside, and display it to the page, then we can directly click on the button to let the contents of the file automatically displayed to the page ....

Without having to go through the process of opening a new window.

Similarly, we click on the Save button, we can directly give the file name as you want, and directly saved to the location or file you want ....

Instead of opening a new window to locate a specific folder under this step?


Here is how to achieve such a one step:

The first is to open the file and display the contents of the file:

(directly to the text content in all. txt files in the AppData directory and displayed on the page)

Traverse the AppData directory to get all the files Storagefolder folder = ApplicationData.Current.LocalFolder; Take all the files in folder folders (Getfilesasync ())//In fact there are corresponding to take a file (Getfileasync ()) var fileList = await folder.            Getfilesasync ();            list<string> notelist = new list<string> (); foreach (var file in fileList) {//The following three lines are the suffix of the file, because only the. txt file can be taken here, int length = f Ile. Path.tostring ().                Length; int pointindex = file. Path.tostring ().                IndexOf ("."); String name = file. Path.tostring ().                Substring (PointIndex + 1, 3); if (name = = "txt") {notelist. ADD (file.                    Name);                    Reads the text contents of the text file inside the string str = await fileio.readtextasync (file);                Place the read text content in the foreground text box (Txtcontent is the unique identifier of the foreground text box) Txtcontent.text + = str;           }}//This side listviewbind is the unique identification of the foreground listview space Listviewbind. ItemsSource = notelist;

Then save the file:

(The GUID implementation is not repeated, and the text is written directly to the file and saved to the specified location)

GUIDs are a series of strings that are automatically generated with information such as Computer Configuration and so on, with a repetition rate of almost 0            //or a generic database, or a file naming requirement that does not have a duplicate name, the GUID            string guid = Guid.NewGuid () is used. ToString (). Substring (0, 5);            Navigate to the current app's AppData directory            Storagefolder folder = ApplicationData.Current.LocalFolder;            In this directory, create the file Filejson, which is the first 5 characters generated by the GUID above (make sure not to repeat)            StorageFile Filejson = await folder. Createfileasync (GUID + ". txt");            if (Filejson! = null)            {                //takes out the data in the Foreground text box (this is to be persisted to the file),                string str = txbContent.Text.ToString (). Trim ();                Write data to file, save                await Fileio.writetextasync (Filejson, str);            }

The above is the code that can be skipped to open and save the file by opening a new window

Although very rough, but very can explain the problem, there is I Google or Baidu for a long time, found that many great gods also have other methods and operations, feel that they are still very weak, or to continue to work hard, really is the boundless.


Win8 do not open and save the file through a new open window, click to display the text content, click to save the file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.