vb.net读配置文件,vb 配置文件

vb.net中,读取和写入文件

写入:Dim sr As New IO.StreamWriter(Application.StartupPath "/写入的文本.txt")

香河网站建设公司创新互联公司,香河网站设计制作,有大型网站制作公司丰富经验。已为香河近千家提供企业网站建设服务。企业网站搭建\外贸网站制作要多少钱,请找那个售后服务好的香河做网站的公司定做!

sr.WriteLine("写入的内容") sr.Close()读取:If (File.Exists(Application.StartupPath "/msg.txt")) Then

Dim fm As New IO.FileStream(Application.StartupPath "/读取的文本.txt", FileMode.Open)

Dim sr As IO.StreamReader = New IO.StreamReader(fm)

Do While sr.Peek() = 0

TextBox1.Text = sr.ReadLine() (读取文本到文本框)

Loop end if

vb.net 2.0 如何用Configuration.ConfigurationSettings.AppSettings读取配置文件中的内容?

使用ConfigurationSettings.AppSetting读取,如下例

Imports System.Configuration

Private ReadOnly db As String = ConfigurationSettings.AppSettings("DB")

vb.net如何读取服务器上的文件。把文件读出来……

楼上的继续忽悠人吧。2,3句搞定的东西弄这么复杂。。。

就是读取服务器文件呀。

微软论坛就有例子。

Imports System

Imports System.IO

Class Test

Public Shared Sub Main()

Try

' 创建一个实例的StreamReader阅读从一个文件。

Dim sr As StreamReader = New StreamReader("TestFile.txt")

Dim line As String

' 阅读并显示线路从文件,直到最后

' 该文件被达成。

Do

line = sr.ReadLine()

Console.WriteLine(Line)

Loop Until line Is Nothing

sr.Close()

Catch E As Exception

' 让用户知道有什么地方出了差错。

Console.WriteLine("The file could not be read:")

Console.WriteLine(E.Message)

End Try

End Sub

End Class

//上面是微软的例子,你可以参考自己改,下面是我改的。

Imports System.IO

Partial Class test

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Using sr As StreamReader = New StreamReader("E:\新建文本文档.txt", Encoding.GetEncoding("gb2312"))

Response.Write(sr.ReadLine())

End Using

End Sub

End Class

已经测试过了,文件路径自己改,支持TXT格式,其他格式自己修改编码

求大神指点 vb.net 怎么读 ini 配置呢

VB.NET读写INI配置文件

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim path As String

path = Application.StartupPath + "\Send.ini"

TextBox1.Text = GetINI("Send", "Send1", "", path)

TextBox2.Text = GetINI("Send", "Send2", "", path)

Dim IsSms As Integer = GetINI("Send", "IsSms", "", path)

If (IsSms = 1) Then

Me.RadioButton1.Checked = True

ElseIf (IsSms = 0) Then

Me.RadioButton2.Checked = True

End If

End Sub

Public Function GetINI(ByVal Section As String, ByVal AppName As String, ByVal lpDefault As String, ByVal FileName As String) As String

Dim Str As String = LSet(Str, 256)

GetPrivateProfileString(Section, AppName, lpDefault, Str, Len(Str), FileName)

Return Microsoft.VisualBasic.Left(Str, InStr(Str, Chr(0)) - 1)

End Function

Public Function WriteINI(ByVal Section As String, ByVal AppName As String, ByVal lpDefault As String, ByVal FileName As String) As Long

WriteINI = WritePrivateProfileString(Section, AppName, lpDefault, FileName)

End Function

Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Int32, ByVal lpFileName As String) As Int32

Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Int32

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Try

Dim path As String

path = Application.StartupPath + "\Send.ini"

WriteINI("Send", "Send1", TextBox1.Text, path)

WriteINI("Send", "Send2", TextBox2.Text, path)

If (Me.RadioButton1.Checked = True) Then

WriteINI("Send", "IsSms", 1, path)

ElseIf (Me.RadioButton2.Checked = True) Then

WriteINI("Send", "IsSms", 0, path)

End If

MsgBox("配置设置已经成功!!!!")

Catch ex As Exception

MsgBox("错误!!!!")

End Try

End Sub

VB.NET2010读取INI配置文件问题?

设计功能

说明:第一个参考页导入了System.IO

功能sdGetIniInfo(字符串的BYVAL iniSection的字符串,BYVAL INIFILE),如果该字符串/ File.Exists (INIFILE返回的“文件”INIFILE的的)

,而“未找到,以确保路径和文件名是否正确!”如果

黑暗iniRead

昏暗的iniStr新的StreamReader(INIFILE),的字符串iniRead.ReadToEnd

朦胧朦胧的整数

最后的出口,克莱因整数

昏暗的NOSEC布尔=假

作为一个字符的字符串昏暗的getValue“

黑暗的壁橱

衣柜iniStr.Split(CHR(13 ))CLINE = UBOUND功能的(CLST)

= 0 CLINE

衣柜(I)的indexOf(“=”) 0,

衣柜(I)分裂(“=”) (0)TRIM()= iniSection

NOSEC =

的getValue = CLST(I)分裂(“=”;)(1)修剪()

BR /退出

最后,如果

如果NOSEC = TRUE

返回的getValue BR /

的安装信息没有找到“iniSection!”

功能

====如果=================== ===================

TEXT1 = sdGetIniInfo(路径,“名称”)

事实上,无论是ini文本文件XML只使用一定的格式,或所谓的数据结构,在最后的分析中,实现的文件操作的功能只是一个包文件的读取和写入操作。

是不是写一个函数的API!


本文名称:vb.net读配置文件,vb 配置文件
标题链接:http://azwzsj.com/article/heihhp.html