如何使用数据库路径检索存储在文件夹中的文档 [英] how can i retrieve documents stored on a folder using the database path

查看:65
本文介绍了如何使用数据库路径检索存储在文件夹中的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码将文档存储在文件夹中,路径存储在ms-access数据库中。它的工作原理可能会对你有所帮助。但我不知道如何使用存储在数据库中的路径检索文件?任何人都知道这一点请给我一些提示

 使用 OpenFileDialog1 
。标题= 请选择一个文件
.InitialDirectory = C:temp
.Filter = 选择文件| * .pdf * |(*)| * .doc; * .txt; * .rtf; * .xls
.FilterIndex = 1
.ShowDialog()

结束 With
Dim sourcepath As String = DocPathTextBox.Text
Dim DestPath As String = D:\\\\
如果 Directory.Exists(DestPath)然后
Directory.CreateDirectory(DestPath)
结束 如果
Dim file = FileInfo(DocPathTextBox.Text)
file.CopyTo(Path.Combine(DestPath,file.Name), True
DocPathTextBox.Text = Path.Combine(DestPath,file.Name)

解决方案

< blockquote>这假设您正在尝试读取文件并获取存储在其中的文件,您的问题没有说明您要对文件执行的操作。



使用streamreader获取文件并读取值



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



  //  连接数据库并查询你的表 
// 获取存储在数据库中的路径
// 假设您的字段是FilePath而您的DataReader是drFiles
string filePath = drFiles [ FilePath]
使用(StreamReader sr = new StreamReader(filePath))
{
string 行;
// 读取并显示文件中的行直到
< span class =code-comment> // 文件已到达。
((line = sr.ReadLine())!= null
{
Console.WriteLine(line);
}
}





 ' 连接数据库并查询表格 
' 获取存储在数据库中的路径
' 假设您的字段是FilePath,您的DataReader是drFiles
dim filePath as string = drFiles( FilePath
使用 sr 作为 new StringReader( filePath)
dim line as string = sr.ReadLine()
do while nothing
Console.WriteLine(line)
loop
end 使用


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

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)

解决方案

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[^]

// 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);
    }
}



' 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


这篇关于如何使用数据库路径检索存储在文件夹中的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆