Question Windows Forms Application

jmt60

New member
Joined
Aug 3, 2010
Messages
2
Programming Experience
Beginner
Hello,

I am building a vb.net application with VS2010. The aim of the application is to change sln. files from VS2005/2008 versions into VS2010.
I am using a Form with 2 text boxes and 2 buttons. When I click the 1st button it reveals the sln file in the text box. Then i have a 'convert' button that I want to use to 'convert' the file that appears in the first text box. I have come quite far with the source code but am just a bit puzzled as to how i can retrieve the VS2005 sln files and to get the 'convert' button to display the text in the 2nd text box.
Maybe someone could help me with some code?

I have included my code thus far. I would really appreciate the help.

Imports System
Imports System.IO
Public Class Form1
Private s_FileName As String
Private FileContent As String
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim filedialog As New OpenFileDialog
With filedialog
.Filter = "sln files (*.sln)|*.sln"
End With
If filedialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
LoadFile(filedialog.FileName)
Else
MessageBox.Show("niet de juiste versie")
End If
End Sub
Private Sub LoadFile(ByVal filename As String)
If File.Exists(filename) Then
s_FileName = filename
Dim sr As StreamReader = Nothing
Try
sr = New StreamReader(filename)
FileContent = sr.ReadToEnd
If isSolutionCorrectVersion() Then
TextBox1.Text = FileContent
Else
MessageBox.Show("niet de juiste versie")
FileContent = String.Empty
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If Not sr Is Nothing Then
sr.Close()
End If
End Try
Else
MessageBox.Show(filename & " bestand niet gevonden", "VS2010-2005 Converter", MessageBoxButtons.OK)
End If
End Sub

Private Function isSolutionCorrectVersion() As Boolean
Dim verString As String = "Microsoft Visual Studio Solution File, Format Version 11.00"
Dim stString As String = "# Visual Studio 2010"
If FileContent.Contains(verString) And FileContent.Contains(stString) Then
Return True
Else
Return False
End If
End Function
Private Sub ChangeSolution()
Dim fileContentLines() As String = FileContent.Split(vbCrLf)
Dim value1 As String = "Microsoft Visual Studio Solution File, Format Version 11.00"
For i As Integer = 0 To fileContentLines.Length - 1
If fileContentLines(i).Contains(value1) Then
fileContentLines(i) = fileContentLines(i).Replace("11.00", "9.00")
ElseIf fileContentLines(i).Contains("# Visual Studio 2010") Then
fileContentLines(i) = fileContentLines(i).Replace("# Visual Studio 2010", "# Visual Studio 2005")
End If
Next
useStreamWriter(fileContentLines)
End Sub
Private Sub useStreamWriter(ByVal fileContententLines() As String)
Dim oWrite As System.IO.StreamWriter = Nothing
Try
oWrite = New StreamWriter(s_FileName, False)
For Each line As String In fileContententLines
oWrite.WriteLine(line)
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
oWrite.Close()
End Try
End Sub
End Class
 
Back
Top