Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 646
  • Last Modified:

Write an ini File using vb.net

I need to write a ini file using vb.net.
it should be like this.
ipaddress=some ipaddress
document number=docid

[doc id]
file1=location of file.
and then rename the file as
3 Solutions
Does it really need to be an INI file?   A typical VB.Net applicaiton would use a *.config file to store this type of information.  The config file is completely automated via the My.Settings class... and it very easy to setup and use.
DattuAuthor Commented:
Its not a config or any sort of config file. it needs to be read by another file client server and that server can read only ini files.
käµfm³d 👽Commented:
The easiest way in .NET would be to create a StreamWriter object and just write the file in .ini format. If you are hard-pressed to actually use Windows Ini api, then you could use Interop to call the appropriate API functions:
Imports System.Runtime.InteropServices
Imports System.Text

Public Class Ini
    <DllImport("kernel32.dll", SetLastError:=True)> _
Private Shared Function WritePrivateProfileString(ByVal lpAppName As String, _
                        ByVal lpKeyName As String, _
                        ByVal lpString As String, _
                        ByVal lpFileName As String) As Boolean
    End Function

    <DllImport("kernel32.dll", SetLastError:=True)> _
    Private Shared Function GetPrivateProfileString(ByVal lpAppName As String, _
                            ByVal lpKeyName As String, _
                            ByVal lpDefault As String, _
                            ByVal lpReturnedString As StringBuilder, _
                            ByVal nSize As Integer, _
                            ByVal lpFileName As String) As Integer
    End Function
End Class

Open in new window

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Mike TomlinsonMiddle School Assistant TeacherCommented:
(I like the other options better)

Using kaufmed's StreamWriter approach:
        Dim user As Integer = 1
        Dim ipaddress As String = ""
        Dim docid As String = "123abc"

        Using sw As New System.IO.StreamWriter("c:\some\path\file.ini")
            sw.WriteLine("user=" & user)
            sw.WriteLine("ipaddress=" & ipaddress)
            sw.WriteLine("document number=" & docid)
            ' etc...
        End Using

Open in new window

Éric MoreauSenior .Net ConsultantCommented:
DattuAuthor Commented:
I wish I could give 125 points to all of you. sorry guys!

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now