如何在不使用保存文件对话框的情况下覆盖文本文件? [英] How to overwrite text file without using Save file dialog?

查看:79
本文介绍了如何在不使用保存文件对话框的情况下覆盖文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在使用VB 2008而且我遇到了问题。



我正在制作一个html编辑器并制作语法等所有内容。

但我知道如何保存文件,但我不知道如何覆盖它。就像'当你正在编辑文本文件时,按ctrl + s它会自动保存。

怎么办?谢谢你提前帮忙。



KrishGM

Hi everyone, I'm using VB 2008 and I'm having problems.

I'm making a html editor and made everything like syntax, etc.
but I know how to save a file, but I don't know how to overwrite it. like'when you're editing a text file, you press ctrl+s and it automatically saves.
how to do that? thanks for helping in advance.

KrishGM

推荐答案

只需编写文件。

File.WriteAllText [ ^ ]只需要你提供文件的路径和要写入的数据(还有其他File.WriteXXX方法对不同类型的数据执行相同操作) - 如果您已经有文件名和路径,则无需再次询问 - 只需调用适当的方法并编写它。



尽管提供备份工具是个好主意:将文件写入同一文件夹中的临时文件,然后重命名原始,然后重命名新文件。这样,如果用户的更新导致问题,用户可以退后一步。
Just write the file.
File.WriteAllText[^] just needs you to supply the path to the file, and the data to write (and there are other File.WriteXXX methods that do the same for different types of data) - provided you have a file name and path already, you don't need to ask again - just call the appropriate method and it's written.

It's a good idea to provide a backup facility though: write the file to a temporary file in the same folder, then rename the original, then rename the new file. That way, the user can "step back" if his updates caused a problem.


这篇关于如何在不使用保存文件对话框的情况下覆盖文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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