Win8.1 file operations for application development, win8.1 Application Development Operations

Source: Internet
Author: User

Win8.1 file operations for application development, win8.1 Application Development Operations

Before operating the fileApplication function declaration. You can access files on win8.1 through C # (non-UI). It can only be confined to Four folders: images, music, videos, and documents. The file selector can access the entire system file.

(1) application function declaration

For the win8 App Store app, open the Package. appxmanifest file, click the "function" tab, and select "music library", "Image Library", and "Video Library". In this way, you can perform operations on the files and folders in the file by using the code:


Music
MusicLibrary allows users to access user music by programming, allowing applicationsNo user interaction requiredYou can enumerate and access all files in the database. This license is generally used in an automatic recording recorder application that requires access to the entire music library.
File picker provides a powerful UI mechanism for users to open files to be processed by an application. You must declare the musicLibrary license only when the application requires programmatic access and file picker cannot implement programmatic access.


Image
The range of picturesLibrary permits users to access images programmatically, allowing applications to enumerate and access all files in the library without user interaction. This license scope is generally used in the photo playing application that requires access to the entire image library.
File picker provides a powerful UI mechanism for users to open files to be processed by an application. Define the picturesLibrary license only when the application requires programmatic access and file picker cannot implement programmatic access.


Video
VideosLibrary allows users to program video access, allowing applications to enumerate and access all files in the library without user interaction. This license is generally used in movie play applications that require access to the entire video library.
File picker provides a powerful UI mechanism for users to open files to be processed by an application. The scope of videosLibrary permission should be declared only when the application requires programmatic access and file picker cannot implement programmatic access.


ForDocument"To access the folder, you must set it automatically based on the error information provided by VS. Then, you must set file association and follow the prompts.


(2) file Selector

UI to access files on the entire system. Use the file selector to allow users to select files and folders to access files and folders. You can use the FileOpenPicker class to obtain access to files and use FolderPicker to obtain access to folders. Through the file selector, your application can access files and folders on the user's entire system. When you call the file selector, you can browse its system and select a file (or folder) to access and save. After a user selects a file or folder, your application receives the selection as a StorageFile and StorageFolder object. Then, your application can operate on the selected files and folders by using these objects.

if (rootPage.EnsureUnsnapped()){    FileOpenPicker openPicker = new FileOpenPicker();    openPicker.ViewMode = PickerViewMode.Thumbnail;    openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;    openPicker.FileTypeFilter.Add(".jpg");    openPicker.FileTypeFilter.Add(".jpeg");    openPicker.FileTypeFilter.Add(".png");    StorageFile file = await openPicker.PickSingleFileAsync();    if (file != null)    {        // Application now has read/write access to the picked file        OutputTextBlock.Text = "Picked photo: " + file.Name;    }    else    {        OutputTextBlock.Text = "Operation cancelled.";    }}

(3) program file operations

Class KnownFolders provides access to common locations that contain user content. This includes content, removable devices, home groups, and media server devices in your local library (such as photos, documents, music, or videos. For access to disk files, this is limited to four folders: images, music, documents, and videos.

Example 1: download an object from the server to a subfile in the "image" folder (which must be dynamically created ).

String dync_IPv4 = "211.87.237.23"; string port = "8081"; string UrlJsonPath = "json/Images.txt"; // string UrlJsonPath = "Image/694021692/1214936171 .png"; string uri =" http: // "+ dync_IPv4 +": "+ port +"/"+ UrlJsonPath; System. diagnostics. debug. writeLine (uri); string filename = "ImagesUri.txt"; // string filename = "DAXIA.png"; var rass = RandomAccessStreamReference. createFromUri (new Uri (uri); IRandomAccessStream inputStream = await rass. openReadAsync (); Stream input = WindowsRuntimeStreamExtensions. asStreamForRead (inputStream. getInputStreamAt (0); try {// get the Guid of the image extension StorageFolder folder = KnownFolders. picturesLibrary; // System. diagnostics. debug. writeLine (folder. path); // Creates a new file in the current folder, and specifies what to do if a file with the same name already exists in the current folder. storageFolder childFolder = await folder. createFolderAsync ("WhereWeGo"); StorageFile outputFile = await childFolder. createFileAsync (filename, CreationCollisionOption. replaceExisting); // StorageFile outputFile = await folder. createFileAsync (filename, CreationCollisionOption. replaceExisting); System. diagnostics. debug. writeLine (outputFile. path); using (IRandomAccessStream outputStream = await outputFile. openAsync (FileAccessMode. readWrite) {Stream output = WindowsRuntimeStreamExtensions. asStreamForWrite (outputStream. getOutputStreamAt (0); await input. copyToAsync (output); output. dispose (); input. dispose () ;}} catch (Exception) {System. diagnostics. debug. writeLine ("adfasd ");}

Example 2: connect to Example 1 to read the downloaded file.

// Obtain the specified file StorageFolder storageFolder = KnownFolders in the specified directory. picturesLibrary; StorageFolder folder = await storageFolder. getFolderAsync ("WhereWeGo"); StorageFile storageFile = await folder. getFileAsync ("ImagesUri.txt"); // StorageFile storageFile = await storageFolder. getFileAsync ("ImagesUri.txt"); if (storageFile! = Null) {// obtain the text content in the specified file string textContent = await FileIO. readTextAsync (storageFile, Windows. storage. streams. unicodeEncoding. utf8); System. diagnostics. debug. writeLine (textContent );}



When you double-click win81 to open the folder, there is no relevant program to perform the operation. How can I restore the settings?

1. If hidden files such as autorun. inf are stored in each partition, delete the files and restart the computer. 2. re-set the open mode in the file type (take XP as an example) find "Drive" or "folder" for the file type "open my computer tools" and "Folder Options" (select which one depends on your problem and select "Drive" if you cannot open the drive by double-clicking it .) "OK. then return to the "edit file type" window, select "open" and set it to default ". OK (now open the partition or folder and check whether the file has been restored to normal?




How can I display all the folders in win81 with a medium icon?


That's simple.


 

Related Article

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.