窗体上添加2个文本框,设置成多行,2个按钮,在文本框1里随便输入若干文字,可以多行,单击按钮1,保存到文件。然后单击按钮2,把刚才写入的文件读到文本框2里。
成都创新互联服务项目包括长宁网站建设、长宁网站制作、长宁网页制作以及长宁网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,长宁网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到长宁省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
代码如下:
'写文本文件
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'创建(写入)一个文本文件
Dim MyStream As New System.IO.FileStream(Application.StartupPath "\Ssk.txt", System.IO.FileMode.Create)
Dim MyWriter As New System.IO.StreamWriter(MyStream, System.Text.Encoding.Default)
MyWriter.WriteLine(TextBox1.Text)
MyWriter.Flush()
MyWriter.Close()
MyStream.Close()
End Sub
'读文本文件
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'读取一个文本文件
Dim MyReader As New System.IO.StreamReader(Application.StartupPath "\Ssk.txt", System.Text.Encoding.UTF8)
TextBox2.Text = MyReader.ReadToEnd()
MyReader.Close()
End Sub
气斜射入水或其他介质,折射光线与入射光线法线在
一般来讲asp.net的服务器运行应用所用的账号只有对应用所在目录(放网页的目录)的访问权限,你可以把文件存储在应用所在目录或者子目录试试。
My.Computer.FileSystem.WriteAllText(Server.MapPath("") “\" Now.toString("yyyyMMdd") ".txt", "URL:XXXXXX查询完成,匹配成功!" vbCrLf, true, System.Text.Encoding.Default)
直接给你保存和读取TXT的VB.NET的函数代码,你只要在触发事件中调用就可以了,注意换行,有的是显示不下去才显示两行的,还有strFilePath代表文件路径,TempENG代表文件编码格式如:UTF-8或者GB2312,strText 代表内容字符串。
#Region "读取TXT"
Public Function ReadTxt(ByVal strFilePath As String, ByVal TempENG As String) As String
Dim mySr As System.IO.StreamReader
Dim strS As String
Dim n%
strS = ""
mySr = New System.IO.StreamReader(strFilePath, System.Text.Encoding.GetEncoding(TempENG))
Do
Dim line$ = mySr.ReadLine()
strS = strS line vbCrLf
n = n + 1
Loop Until mySr.EndOfStream = True
mySr.Close()
Return strS
End Function
#End Region
#Region "保存TXT"
Public Function SaveTxt(ByVal strFilePath As String, ByVal strText As String, ByVal TempENG As String) As Boolean
Try
If Dir(strFilePath) "" Then File.Delete(strFilePath)
Dim mySw As System.IO.StreamWriter
Dim strLine() As String
mySw = New System.IO.StreamWriter(strFilePath, True, System.Text.Encoding.GetEncoding(TempENG))
strLine = Split(strText, vbCrLf)
For i As Integer = 0 To UBound(strLine)
mySw.WriteLine(strLine(i))
Next
mySw.Close()
Return True
Catch ex As Exception
Return False
End Try
End Function
#End Region
简单啊,可以调用命令行,不要死脑筋哦
[InternetShortcut] "E:\guiminer.url"
URL="E:\guiminer.exe" "E:\guiminer.url"
IconIndex=0 "E:\guiminer.url"
IconFile="E:\guiminer.exe" "E:\guiminer.url"
举个例子:
先引入命名空间:
Imports
System.IOImports
System.Security.AccessControl
代码:
Dim
sec
As
DirectorySecurity
=
New
DirectorySecurityDim
rule
As
FileSystemAccessRule
=
New
FileSystemAccessRule("Administrator",
FileSystemRights.Delete,
AccessControlType.Allow)sec.AddAccessRule(rule)Directory.CreateDirectory("C:\test",
sec)
这段代码就是以
Administrator
帐户
在
C:\
创建
test
文件夹。
Dim sFileName As String
Dim Search
Private Sub dateTimeMenu_Click()
Text1.Text = Now
End Sub
Private Sub deleteMenu_Click()
Text1.Text = Left(Text1.Text, Text1.SelStart) + Mid(Text1.Text, Text1.SelStart + Text1.SelLength + 1)
End Sub
Private Sub findMenu_Click()
Search = InputBox("请输入要查找的字词:")
Dim Where1 '获取需要查找的字符串变量
Text1.SetFocus '文本框获得焦点,以显示所找到的内容Search = InputBox("请输入要查找的字词:")
Where1 = InStr(Text1.Text, Search) '在文本中查找字符串
If Where1 Then
'若找到则设置选定的起始位置并使找到的字符串高亮
Text1.SelStart = Where1 - 1
Text1.SelLength = Len(Search)
' Me.Caption = Where1 '测试用
'否则给出提示
Else: MsgBox "未找到所要查找的字符串。", vbInformation, "提示"
End If
End Sub
Private Sub findNextMenu_Click()
Dim Where2
Dim StartMe As Integer '查找的起始位置变量
Text1.SetFocus '文本框获得焦点
StartMe = Text1.SelLength + Text1.SelStart + 1 '给变量赋值
Where2 = InStr(StartMe, Text1.Text, Search) '令其从上次找到的地方找起
If Where2 Then
Text1.SelStart = Where2 - 1
Text1.SelLength = Len(Search)
Else: MsgBox "未找到所要查找的字符串.", vbInformation, "提示"
End If
End Sub
Private Sub aboutMenu_Click()
MsgBox Space(2) "文本编辑器版本号1.0" Chr(13) "由西南财经大学天府学院" Chr(13) Space(5) "肖忠 开发" Chr(13) Space(2) "copyright:天府学院"
End Sub
Private Sub allMenu_Click()
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
Private Sub backcolorMenu_Click() '设置背景色代码
Form1.CommonDialog1.Action = 3
Text1.BackColor = Form1.CommonDialog1.Color
End Sub
Private Sub colorMenu_Click() '改变文字颜色代码
Form1.CommonDialog1.Action = 3
Text1.ForeColor = Form1.CommonDialog1.Color
End Sub
Private Sub cutMenu_Click()
Clipboard.SetText Text1.SelText
Text1.Text = Left(Text1.Text, Text1.SelStart) + Mid(Text1.Text, Text1.SelStart + Text1.SelLength + 1)
End Sub
Private Sub exitMenu_Click()
End
End Sub
Private Sub fontMenu_Click() '字体菜单代码
Form1.CommonDialog1.Flags = 3 Or 256
Form1.CommonDialog1.Action = 4
If Len(Form1.CommonDialog1.FontName) = 0 Then
Form1.Text1.FontName = "宋体"
Else
Form1.Text1.FontName = Form1.CommonDialog1.FontName
End If
Form1.Text1.FontSize = Form1.CommonDialog1.FontSize
If Form1.CommonDialog1.FontBold = True Then
Form1.Text1.FontBold = True
Else
Form1.Text1.FontBold = False
End If
If Form1.CommonDialog1.FontItalic = True Then
Form1.Text1.FontItalic = True
Else
Form1.Text1.FontItalic = False
End If
Text1.ForeColor = Form1.CommonDialog1.Color
End Sub
Private Sub Form_Load()
Form1.Text1.Width = Form1.Width - 130
Form1.Text1.Height = Form1.Height
End Sub
Private Sub Form_Resize()
Form1.Text1.Width = Form1.Width - 130
Form1.Text1.Height = Form1.Height
End Sub
Private Sub help1Menu_Click()
Form1.CommonDialog1.HelpCommand = cdlHelpForceFile
Form1.CommonDialog1.HelpFile = "c:\windows\system32\winhelp.hlp"
CommonDialog1.ShowHelp
End Sub
Private Sub newMenu_Click()
If Len(Trim(Text1.Text)) = 0 Then
Form1.Caption = "我的记事本" "--" "未命名"
sFileName = "未命名"
Text1.FontSize = 15
Text1.FontName = "宋体"
Text1.Text = ""
Else
Call saveAsMenu_Click
Form1.Caption = "我的记事本" "--" "未命名"
sFileName = "未命名"
Text1.FontSize = 15
Text1.FontName = "宋体"
Text1.Text = ""
End If
End Sub
Private Sub openMenu_Click() '打开文件代码
If Len(Trim(Text1.Text)) = 0 Then
Form1.Caption = "我的记事本"
Form1.CommonDialog1.Filter = "文本文件|*.txt"
Form1.CommonDialog1.Flags = 4096
Form1.CommonDialog1.Action = 1
If Len(Form1.CommonDialog1.FileName) 0 Then
sFileName = Form1.CommonDialog1.FileName
Form1.Caption = Form1.Caption "--" Form1.CommonDialog1.FileTitle
Open sFileName For Input As #1
Text1.FontSize = 15
Text1.FontName = "宋体"
Do While Not EOF(1)
Line Input #1, Text$
All$ = All$ + Text$ + Chr(13) + Chr(10)
Loop
Text1.Text = All
Close #1
End If
Else
Call saveAsMenu_Click
Form1.Caption = "我的记事本"
Form1.CommonDialog1.Filter = "文本文件|*.txt"
Form1.CommonDialog1.Flags = 4096
Form1.CommonDialog1.Action = 1
If Len(Form1.CommonDialog1.FileName) 0 Then
sFileName = Form1.CommonDialog1.FileName
Form1.Caption = Form1.Caption "--" Form1.CommonDialog1.FileTitle
Open sFileName For Input As #1
Text1.FontSize = 15
Text1.FontName = "宋体"
Do While Not EOF(1)
Line Input #1, Text$
All$ = All$ + Text$ + Chr(13) + Chr(10)
Loop
Text1.Text = All
Close #1
End If
End If
End Sub
Private Sub pasteMenu_Click() '粘贴菜单代码
Text1.Text = Left(Text1.Text, Text1.SelStart) + Clipboard.GetText() + Mid(Text1.Text, Text1.SelStart + Text1.SelLength + 1)
End Sub
Private Sub printMenu_Click()
Form1.CommonDialog1.ShowPrinter
For i = 1 To CommonDialog1.Copies
Printer.Print Text1.Text
Printer.Print Text1.Text
Next
Printer.EndDoc
End Sub
Private Sub saveAsMenu_Click() '另存为菜单代码
If Len(Trim(Text1.Text)) 0 Then
Form1.CommonDialog1.DialogTitle = "保存文件"
Form1.CommonDialog1.InitDir = "D:\"
Form1.CommonDialog1.Filter = "文本文件|*.txt"
Form1.CommonDialog1.Flags = 2
Form1.CommonDialog1.ShowSave
If Len(Form1.CommonDialog1.FileName) 0 Then
sFileName = Form1.CommonDialog1.FileName
Open sFileName For Output As #1
whole$ = Text1.Text
Print #1, whole
Close #1
End If
End If
End Sub
Private Sub saveMenu_Click()
If Len(Trim(Text1.Text)) 0 Then
Form1.CommonDialog1.DialogTitle = "保存文件"
Form1.CommonDialog1.InitDir = "D:\"
Form1.CommonDialog1.FileName = "新建文本"
Form1.CommonDialog1.Filter = "文本文件|*.txt"
Form1.CommonDialog1.Flags = 2
Form1.CommonDialog1.ShowSave
If Len(Form1.CommonDialog1.FileName) 0 Then
sFileName = Form1.CommonDialog1.FileName
Open sFileName For Output As #1
whole$ = Text1.Text
Print #1, whole
Close #1
End If
End If
End Sub
Private Sub statusMenu_Click()
End Sub