[UWP] [VB]文件已更改&打开,编辑和保存文件时的相同文件名 [英] [UWP][VB]File Changed & Same File Name When Opening, Editing, and Saving a File

查看:108
本文介绍了[UWP] [VB]文件已更改&打开,编辑和保存文件时的相同文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序将允许用户打开,编辑和关闭文本文件。我已经想出了如何毫无问题地完成所有这些工作,但是在编辑我想要添加的文件时,有两件事情通常是非常标准的。


1。让用户知道他们的文件是否已被更改:


我想让用户知道他们是否实际更改了文件。在桌面应用程序中,这通常通过在标题栏中显示文件名旁边的*(或者在允许编辑多个文件的应用程序的选项卡中)来完成。我显然可以保留一个
额外的String变量与文件原来的样子,或者在他们做出改变时设置一个布尔变量,但我想知道是否有更好或更标准的方法。用于通知用户在编辑后他们没有保存
文件的最佳事件是什么?另外,通知用户他们为全屏应用编辑了文档的最佳或最标准的方法是什么?


2。当用户打开文件时,将其保存到同一个文件中:


我的应用程序与许多人一样,允许用户打开现有文件或创建新文件。当用户打开现有文件时,他们很可能希望将其保存到具有相同名称的同一文件中。此外,当用户保存文件时,如果已存在同名文件,我希望他们收到
警告,除非该文件是他们打开的文件。我是否需要手动跟踪这些信息,还是有更高效或标准的方式来做?


这是我的第一个让用户编辑文件的应用程序,所以我感谢任何人都能给予的帮助。谢谢!




Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

解决方案

您好,


1)UWP提供了一些可以监控文件系统的API。有两种方法可以做到这一点。一个是前景通知,另一个是后台任务。根据你的话,似乎使用后台任务更好。请注意,这只会影响音乐,视频等存储库
。您可以先获取存储库,然后启用StorageLibrary.ChangeTracker属性。然后,您可以尝试使用StorageLibraryContentChangedTrigger注册后台任务。它将由不同的
事件触发,例如内容已更改或文件已删除。


您可以在此处获取更多信息:通用Windows平台 - 通用Windows平台应用程序中的文件系统监控   更改
跟踪:更多更好


2)如果您使用的是filesavepicker,系统将发出警告以保存相同的文件。但是如果你不使用它,你可能需要自己跟踪文件信息。


祝你好运,


Roy


My app will allow the user to open, edit, and close text files. I have figured out how to do all of these things with no problem, But there are two things that are usually very standard when editing files that I want to add.

1. Let the user know if their file has been changed:

I want to let the user know if they have actually changed their file. In Desktop apps this is usually done by showing a * next to the filename in the Title Bar (or maybe in a tab for apps allowing editing of multiple files). I can obviously just keep an extra String variable with what the file originally looked like, or set a Boolean variable when they make a change, But I am wondering if there is a better or more standard way. And what are the best events to use to notify the user that they did not save their file after editing it? Also, what is the best or most standard way to notify the user that they have edited their document for full-screen apps?

2. When a user opens a file, save it to the same file:

My app, like many, allows people to open an existing file or create a new one. When the user opens an existing file, they will most likely want to save it to the same file with the same name. Also, when the user saves their file, I want them to receive a warning if a file with the same name already exists, unless that file is the one that they opened. Do I need to keep track of this information manually, or is there a more efficient or standard way to do it?

This is my first app involving letting the user edit files, so I appreciate any help that anybody can give. Thanks!


Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

解决方案

Hi,

1)UWP offer some APIs that could monitor the file system. There are two ways to do that. One is foreground Notifications and another one is background task. Based on your words, it seems the using background task is better. Please note this only affect the StorageLibraries like Music, Video, etc. You could get the StorageLibrary first and enable the StorageLibrary.ChangeTracker Property. Then you could try to register a background task using StorageLibraryContentChangedTrigger. It would be triggered by different events like content changed or file deleted.

You could get more information here:Universal Windows Platform - File System Monitoring in Universal Windows Platform Apps and Change Tracking: More Betterness.

2)If you are using the filesavepicker, the system will give a warning for saving the same file. But if you are not using this, you might need to keep track of the file information yourself.

Best regards,

Roy


这篇关于[UWP] [VB]文件已更改&打开,编辑和保存文件时的相同文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆