peebman2000
Programmer
Hello I’m new to the forum and I’m a beginner programmer working as an intern programmer with the government. I’m researching to find code to be able to upload a text file and convert it into another formatted text file. Below is my code that I’ve coded from scratch. With limited assistance from the other developers here, I’m trying to use File Transform Engine code from to convert the text file. I have two classes, class1 which is the class for the original formatted text and I have class2 which is the class for the formatted text file I wanted to convert too. Button1 is for the upload and the conversion. When I hit button1 I get and error that says (Could not find file 'C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\convert_text_file.txt'.) I’m trying to convert Convert_text_file.txt into dest.txt. Does anyone have any suggestion what I can do to correct this error? I would appreciate the help, thanks.
Imports System.IO
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Security
Imports System.Web.Configuration
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Text
Imports FileHelpers
Imports FileHelpers.DataLink
Imports Class1
Imports Class2
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'when the page is loaded
Label1.Visible = False
If Not Page.IsPostBack Then
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'put user code to initialize the page here
Label1.Visible = True
'upload file
If FileUpload1.HasFile Then
Try
FileUpload1.SaveAs(Server.MapPath("uploads\" & FileUpload1.FileName))
Catch ex As Exception
Label1.Text = "Failed because <br/>" & ex.Message
End Try
Label1.Text = "File uploaded to: <br/>" & FileUpload1.PostedFile.FileName
Else
Label1.Text = "Please select a file to open"
End If
'Dim obj As Object = New Class1
'Dim obj2 As Object = New Class2
Dim link As FileTransformEngine = New FileTransformEngine(GetType(Class1), GetType(Class2))
link.TransformFile("convert_text_file.txt", "dest.txt")
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Label1.Visible = True
'variables
Dim filename As String = "H:\convert_text_file.txt"
Dim textline As String
textline = " "
If System.IO.File.Exists(filename) = True Then
Dim objreader As New System.IO.StreamReader(filename)
Do While objreader.Peek() <> -1
textline = textline & objreader.ReadLine() & vbNewLine
Loop
TextBox1.TextMode = TextBoxMode.MultiLine
TextBox1.Text = textline
Else
Label1.Text = "file does not exist"
End If
Label1.Text = "File has been opened"
End Sub
End Class
Imports System.IO
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Security
Imports System.Web.Configuration
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Text
Imports FileHelpers
Imports FileHelpers.DataLink
Imports Class1
Imports Class2
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'when the page is loaded
Label1.Visible = False
If Not Page.IsPostBack Then
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'put user code to initialize the page here
Label1.Visible = True
'upload file
If FileUpload1.HasFile Then
Try
FileUpload1.SaveAs(Server.MapPath("uploads\" & FileUpload1.FileName))
Catch ex As Exception
Label1.Text = "Failed because <br/>" & ex.Message
End Try
Label1.Text = "File uploaded to: <br/>" & FileUpload1.PostedFile.FileName
Else
Label1.Text = "Please select a file to open"
End If
'Dim obj As Object = New Class1
'Dim obj2 As Object = New Class2
Dim link As FileTransformEngine = New FileTransformEngine(GetType(Class1), GetType(Class2))
link.TransformFile("convert_text_file.txt", "dest.txt")
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Label1.Visible = True
'variables
Dim filename As String = "H:\convert_text_file.txt"
Dim textline As String
textline = " "
If System.IO.File.Exists(filename) = True Then
Dim objreader As New System.IO.StreamReader(filename)
Do While objreader.Peek() <> -1
textline = textline & objreader.ReadLine() & vbNewLine
Loop
TextBox1.TextMode = TextBoxMode.MultiLine
TextBox1.Text = textline
Else
Label1.Text = "file does not exist"
End If
Label1.Text = "File has been opened"
End Sub
End Class