Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to recover the path of a .doc or .txt opened file

Status
Not open for further replies.

curiousvbnet

Programmer
Apr 6, 2007
40
FR
Hi,

I would like to permit a user to insert into a database fields the lines he has selected in a .doc or a .txt file which will be new datas in the database

It is possible the user has already opened a .doc or a txt file and selected lines , how can i test this, because at the first i supposed he opens a .doc or a .txt file by an openFiledialog control, which is not already like this.

For this i need to test if a .doc or a .txt file is already opened and if the user has selected something(one light at least)inside.

If ypou could help me on this point it would be very kind from you.

Here is the code i use until now

Code:
 [blue]Private Sub menu_importer_descripteur_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menu_importer_descripteur.Click[/blue]

        Dim clsinStream As New System.IO.MemoryStream
        Dim ouverturefichier As New OpenFileDialog
        Dim workfile As String = Nothing
        Dim fileword As File
        'If fileword.OpenWrite Then
            uploadfile(workfile)->[red]here is the test i need to improve  [/red]
        Else
            ouverturefichier.Title = "Selection d'un fichier pour l'import dans la base de données"
            ouverturefichier.Filter = "Text Files {*.txt}|*.txt"
            If ouverturefichier.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
                workfile = ouverturefichier.FileName
                System.Diagnostics.Process.Start(workfile)
            Else
                Exit Sub
            End If
           [green] uploadfile(workfile)[/green]
            ' End If
    End Sub

Code:
[blue] Private Function uploadfile(ByVal workfile As String) As Boolean[/blue]

        If File.Exists(workfile) = True Then
            'le fichier existe, on déclare les objets

            Dim bresult As Boolean = True
            Dim ar As StreamReader = New StreamReader(workfile)
            Dim objimport_desc As SqlCommand
            Dim sql_insert As String
            Dim descripteurligne As String
            objConn.Open()


          [green]  sql_insert = " insert into termes(lib_terme,EM,ID_THES) values(@lib_terme, 0," & intNumThes.ToString & ")"
            objimport_desc = New SqlCommand(sql_insert, objConn)
            objimport_desc.Parameters.Add("@lib_terme", "")

[/green]
            'on parcourt toutes les lignes du fichier , chaque ligne étant un descripteur

            Do While ar.Peek >= 0
                descripteurligne = ar.ReadLine

                MessageBox.Show(descripteurligne)


                'on met à jour la valeur du paramètre 
                objimport_desc.Parameters("@lib_terme").Value = descripteurligne

                'on insère un nouvel enregistrement

                Try
                    objimport_desc.ExecuteNonQuery()
                Catch ex As Exception
                    bresult = False
                    MessageBox.Show(ex.Message, "erreur", MessageBoxButtons.OK, MessageBoxIcon.Error)

                End Try

            Loop
            'on ferme les objets
            ar.Close()
            objimport_desc.Dispose()
            objConn.Close()
            objConn.Dispose()
            Return bresult
        Else
            Return False

        End If
    End Function


Here is
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top