Open File for reading "SMDR(backup10-6-2007)"

waraq

Member
Joined
Dec 18, 2006
Messages
23
Location
Harrison, TN
Programming Experience
Beginner
The scenario is this and please bear with me I'm learning this VS.NET 2005 and I'm trying to open a file with a name "SMDR(backup10-6-2007)" I create an instance of the file:
Dim NArchivos As String = Path.GetFullPath("..\..\SMDR(backup10-6-2007)")
Then I did my best to open the fila that exist but for some reason it saying that the file does not exist, and this is my statement:

VB.NET:
If File.Exists(NArchivos) = True Then
            Dim Leer As StreamReader = File.OpenText(NArchivos)
            txtSearch.Text = Leer.ReadToEnd
            Leer.Close()
            Buscar = CompareMethod.Text
            Seleccionar = InStr(dtpEmpezar.Text, txtSearch.Text, Buscar)   andalso InStr(dtpFinalizar.Text, txtSearch.Text, Buscar)
            If Seleccionar = 0 Then
                MsgBox("The Dates " & dtpEmpezar.Text & " and " & dtpFinalizar.Text & " was not found in the file.", 64, "Range Dates Not Found")
                Exit Sub
            End If
            cobLista.Items.Add(Seleccionar - 1)
        Else
            MsgBox("File not found or may be corrupt.", 64, "File not found")
            Exit Sub
        End If
The file is not corrupt or missing. The things is that is not finding the file.

Thank you for your help.

Willy
 
Hey man you can try this if you want.

VB.NET:
Dim fs as FileStream = Nothing
dim reader as StreamReader = Nothing

Try
    fs = New FileStream(YourFilePath, FileMode.Open, FileAccess.Read)
    reader = New StreamReader(fs)
    ' Do your code here
Catch ex as Exception
    MessageBox(ex.Message)
Finally
    If reader IsNot Nothing Then
       reader.Close
       reader.Dispose
    EndIf
    If fs IsNot Nothing Then 
       fs.Close
       fs.Dispose
    EndIf
End Try
 
This is my msgbox respond:
Could not find file 'C:\Document and Settings\Me\Desktop\Howker
Project\Telefono.vb\Telefono.vb\bin\debug\SMDR(backup10-6-2007)'
I don't understand why is divided in two lines this message
this is the actual loctation of the file "C:\Documents and Settings\Me\Desktop\SMDR(backup10-6-2007)"
 
I create the file in the Desktop for the purpose of practice and reading the file. But the true is that this files will be on the C:\Directory.
What is the difference between Environment.GetFolderPath(Environment.SpecialFolde r.DesktopDirectory). and the one I'm using.? Also how can implement the one you show me.?
 
Back
Top