如何在vb.net中保存文件 [英] How to save files in vb.net

查看:106
本文介绍了如何在vb.net中保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 vb.net 中创建应用程序启动器,但我不知道如何保存文件.保存文件,就像为应用程序运行安装程序时执行的文件一样,其中安装程序将应用程序文件保存在程序文件文件夹中.我不是要创建 vb.net 设置,因为我想以可移植的方式运行我的程序.我希望程序做的是在用户单击按钮时将文件放在适当的位置这是我当前的代码:

I'm trying to create an app launcher in vb.net but I do not know how to save files. Save files like the one that is executed when you run a setup for an application wherein the setup will save the application files on program files folder. I'm not trying to create a vb.net setup, because I want to run my program as portable. What I want the program to do is to place the files in their appropriate location when the user clicks a button Here's my current code:

Public Class Nircmd

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'shutdown
    System.Diagnostics.Process.Start("E:\Documents and Settings\Rew\Desktop\Shutdown.lnk")
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    'monitor off
    System.Diagnostics.Process.Start("E:\Documents and Settings\Rew\Desktop\Monitor Off.lnk")

End Sub
End Class

-当然,如果路径不包含指定的文件,它将不起作用.所以我想放置另一个按钮来做到这一点(以保存在所需文件夹中指定的文件.一个简单的语法就可以了.请

-Of course it won't work if the path doesn't contain the file specified. So I want to place another button that would do just that(to save the files specified in the desired folder. A simple syntax will do. Please

推荐答案

我不太明白,但我会试一试.

I don't quite understand, but I'll take a shot.

这将检查 C:\foo\somefile.txt 是否存在,如果不存在,则创建它并写入一些文本:

This will check to see if C:\foo\somefile.txt exists, and if it doesn't, create it and write some text:

If Not System.IO.File.Exists("C:\foo\somefile.txt") = True Then
    Dim file As System.IO.FileStream
    file = System.IO.File.Create("C:\foo\somefile.txt")
    file.Close()
End If
My.Computer.FileSystem.WriteAllText("C:\foo\somefile.txt", "Some text")

如果你想复制或移动一个文件,我想你会想要这样的:

If you want to copy or move a file, I think you'll want something like:

System.IO.File.Copy("C:\foo\somefile.txt", "C:\bar\somefile.txt")

System.IO.File.Move("C:\foo\somefile.txt", "C:\bar\somefile.txt")

这篇关于如何在vb.net中保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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