Click here to Skip to main content
15,908,445 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i use this code to store documents in folders and the path is stored in the ms-access database. it works may be it helps you. but i didn't have any idea how can i retrieve the documents using the path stored in the database? any one know this please give me some hint
VB
With OpenFileDialog1
            .Title = "Please Select a File"
            .InitialDirectory = "C:temp"
            .Filter = "choose Files|*.pdf*|(*)|*.doc;*.txt;*.rtf;*.xls"
            .FilterIndex = 1
            .ShowDialog()

        End With
        Dim sourcepath As String = DocPathTextBox.Text
        Dim DestPath As String = "D:\a\"
        If Not Directory.Exists(DestPath) Then
            Directory.CreateDirectory(DestPath)
        End If
        Dim file = New FileInfo(DocPathTextBox.Text)
        file.CopyTo(Path.Combine(DestPath, file.Name), True)
        DocPathTextBox.Text = Path.Combine(DestPath, file.Name)
Posted
Comments
Ashok19r91d 20-Dec-12 6:35am    
Improve question...
OriginalGriff 20-Dec-12 6:46am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
You don't show any storage in the database, so it's difficult to work out what you need to do to retrieve them...
Use the "Improve question" widget to edit your question and provide better information.
Richard MacCutchan 20-Dec-12 8:53am    
Get the path from the database and use that to open the file and read it. What is the problem?

1 solution

This is assuming you are trying to read the file and get whats stored in it, your question didnt specify what you want to do with the file.

Use a streamreader to get the file and read the values

http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx[^]

C#
// Connect to the database and query your table
// get the path that you stored in the database
// assuming your field is FilePath and your DataReader is drFiles
string filePath = drFiles["FilePath"]
using (StreamReader sr = new StreamReader(filePath))
{
    string line;
    // Read and display lines from the file until the end of
    // the file is reached.
    while ((line = sr.ReadLine()) != null)
    {
        Console.WriteLine(line);
    }
}


VB
' Connect to the database and query your table
' get the path that you stored in the database
' assuming your field is FilePath and your DataReader is drFiles
dim filePath as string = drFiles("FilePath")
using sr as new StringReader(filePath)
    dim line as string = sr.ReadLine()
    do while (Not line is nothing)
        Console.WriteLine(line)
    loop
end using
 
Share this answer
 
v3
Comments
DinoRondelly 20-Dec-12 10:56am    
Thanks for the edit I guess I should have giving him the VB code,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900