Hello everyone.

I'm trying to work with this kind of file: http://www.mediafire.com/?da0ad07pzfogdl0 (you may use Notepad++ to open it)
I think it's a binary data file but I'm not sure.

Anyways what I need to do it's to edit some of the text part inside it.
Example: http://img403.imageshack.us/img403/8017/94022290.jpg

I'd like to edit the "CustAssetSeen-803981731[NUL][STX][NUL][NUL][NUL]1" to "CustAssetSeen-803981731[NUL][STX][NUL][NUL][NUL]2"

If it was a normal text I wouldn't have any problem, but I really don't know what should I use to work with this kind of file.

Thanks for the attention.

So guys using this code I manage to read the file successfully with my program.

    Dim nul As Char = ChrW(0)
        Dim stx As Char = ChrW(2)
        Dim ht As Char = ChrW(9)
        Dim lf As Char = ChrW(10)
        Dim vt As Char = ChrW(11)
        Dim ff As Char = ChrW(12)

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim fileStream As New IO.FileStream("C:\test", IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.None)
            Dim myFileReader As New System.IO.StreamReader(fileStream)
            Dim text As String = myFileReader.ReadToEnd
            myFileReader.Close()
            fileStream.Close()

            If text.Contains("CustAssetSeen-803981731" & nul & vt & nul & nul & nul & "1") = True Then
                Me.ComboBox1.SelectedIndex = 0
            ElseIf text.Contains(CustAssetSeen-803981731" & nul & vt & nul & nul & nul & "0") = True Then
                Me.ComboBox1.SelectedIndex = 1
            End If
        End Sub

And this is what I'm currently use to edit it.

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


                Dim fileStream1 As New IO.FileStream("C:\test", IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.None)
                Dim myFileReader As New System.IO.StreamReader(fileStream1)
                Dim text As String = myFileReader.ReadToEnd
                myFileReader.Close()
                fileStream1.Close()

                If Me.ComboBox1.SelectedIndex = 0 Then
                    If text.Contains("CustAssetSeen-803981731" & nul & vt & nul & nul & nul & "0") = True Then
                        text = text.Replace("CustAssetSeen-803981731" & nul & vt & nul & nul & nul & "0", "CustAssetSeen-803981731" & nul & vt & nul & nul & nul & "1")
                        MsgBox("Done") 
                    End If
                End If
                Dim fileStream2 As New IO.FileStream("C:\test", IO.FileMode.Create, IO.FileAccess.Write, IO.FileShare.None)
                Dim myFileWriter As New System.IO.StreamWriter(fileStream2)
                myFileWriter.Write(text)
                myFileWriter.Close()
                fileStream2.Close()
                MsgBox("Done")
            End Sub

I know they aren't really optimized but both for now work. My program read and write the file without any issue. Well there's an issue, if I try to run the application which create and manage the file it won't recognize the file.

Any suggestion?

So I've solved it by myself. Here's how:

    Dim fileStream1 As New IO.FileStream(SettingsFile, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.None)
            Dim myFileReader As New System.IO.BinaryReader(fileStream1)
            Dim content As Byte() = myFileReader.ReadBytes(fileStream1.Length)
            Dim text As String = Encoding.Default.GetString(content)
            myFileReader.Close()
            fileStream1.Close()


    Dim fileStream2 As New IO.FileStream(SettingsFile, IO.FileMode.Create, IO.FileAccess.Write, IO.FileShare.None)
            Dim myFileWriter As New System.IO.BinaryWriter(fileStream2)
            Dim b As Byte() = Encoding.Default.GetBytes(text)
            myFileWriter.Write(b)
            myFileWriter.Close()
            fileStream2.Close()

Thanks anyways :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.