Learn how to a build a cloud-first strategyRegister Now

x
  • 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.
[indexes]
user=1
ipaddress=some ipaddress
document number=docid

[doc id]
filetype=type
file1=location of file.
index.ini.
and then rename the file as
0
Dattu
Asked:
Dattu
3 Solutions
 
grayeCommented:
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.
0
 
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.
0
 
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

0
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 = "1.1.1.1"
        Dim docid As String = "123abc"

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

Open in new window

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

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