Recently in busy ASP. NET MVC development has not been free to update the UWP this piece, but sometimes the words still need to share their experience and everyone, in order to progress together.
In the previous chapter, "UWP Development Template10 Practice: An MVVM instance of local file and camera file operations (text-to-document)" has already talked about using Fileopenpicker for file selection and Cameracaptureui for taking pictures.
For file selection, the following settings are generally implemented:
// Select multiple Files New Fileopenpicker (); = Pickerviewmode.thumbnail; = pickerlocationid.pictureslibrary; OpenPicker.FileTypeFilter.Clear (); OPENPICKER.FILETYPEFILTER.ADD ("*"); var await openpicker.pickmultiplefilesasync ();
For the camera function I think we generally only do the following settings:
// take photos Cameracaptureu I Captureui = new Cameracaptureui (); CaptureUI.PhotoSettings.Format = Cameracaptureuiphotoformat.png; captureUI.PhotoSettings.AllowCropping = false ; var photo = await Captureui.capturefileasync (Cameracaptureuimode.photo); if (Photo! = null ) {//File operations (except movement)
}
If you're only moving photos, do your apps take up more space over time?
Because photo files are cached by the photos feature, if the app exits without cleanup, it's likely to stay in the tempstate folder, with more and more photos accumulating over time, and it can easily lead to the app leaking personal information.
For example, "UWP development Template10 Practice: Local file and Camera file operation of the MVVM instance (text to pay the original code)" To do the application, now go to see the app's Tempstate folder, the photos are still in, very scary right?
For UWP data storage It's important to look at Microsoft's introduction: https://msdn.microsoft.com/zh-cn/library/windows/apps/hh464917
The difference between tempstae and localcache :http://stackoverflow.com/questions/34046509/ What-is-the-difference-and-similarity-if-any-between-localcache-and-tempstate
For tempstate temporary application Data Microsoft's statement is:
Temporary app data stores are similar to caches. Its files do not roam and can be deleted at any time. system maintenance tasks can automatically delete data stored at this location at any time. Users can also use Disk Cleanup to purge files in the temporary data store. Temporary app data can be used to store temporary information during an app session. There is no guarantee that this data will persist beyond the end of the app session, because the system may reclaim the space used if necessary.
---that is, if the system is not cleaned up in time, this data will always exist (as in My computer's case)! ---it is for this reason it is necessary to do the removal process manually!
Correct use of temp directory (photo function, etc.):
Approximate steps: Apply startup, clean up temp directory (if this step is ignored from suspend recovery), file operation in temp directory (such as start photo, etc.), apply exit, Clean temp directory (ignore this step if app hangs)
The code is as follows:
Try { await ApplicationData.Current.ClearAsync ( applicationdatalocality.temporary); } Catch { // Cleanup Temp directory exception without doing any processing }
Code location According to the actual application of reasonable choice!
Template10 Practice of UWP Development II: Do you use the camera function properly? (Tempstate temp directory issue)