2017-02-10 21 views
0

我有以下代码将数据从我的计算机上的任何位置上载到名为Documents的列中,数据类型为nvarchar(255),SQL Server中的表中作为文件路径。上传,检索PDF,DOC和图像到SQL Server

如何在表格中加载到Document列的文件路径,并在需要点击Open按钮时检索它? [见下面的截图]

我要完成这样的事情每个记录

Image

Save按钮,点击保存到数据库文件路径

这里是我想要的代码使用

List<string> pdfFiles = new List<string>(); 

private void button1_Click(object sender, EventArgs e) 
{ 
    OpenFileDialog openFileDialog = new OpenFileDialog(); 
    openFileDialog.CheckFileExists = true; 
    openFileDialog.AddExtension = true; 
    openFileDialog.Multiselect = true; 
    openFileDialog.Filter = "PDF files (*.pdf)|*.pdf"; 

    if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) 
    { 
     pdfFiles = new List<string>(); 

     foreach (string fileName in openFileDialog.FileNames) 
      pdfFiles.Add(fileName); 
    } 
} 

private void button2_Click(object sender, EventArgs e) 
{ 
    string installedPath = Application.StartupPath + "pdf"; 

    // Check whether folder path is exist 
    if (!System.IO.Directory.Exists(installedPath)) 
    { 
     // If not create new folder 
     System.IO.Directory.CreateDirectory(installedPath); 
    } 

    // Save pdf files in installedPath 
    foreach (string sourceFileName in pdfFiles) 
    { 
     string destinationFileName = System.IO.Path.Combine(installedPath, System.IO.Path.GetFileName(sourceFileName)); 
     System.IO.File.Copy(sourceFileName, destinationFileName); 
    } 
} 
+0

毫无疑问这里。请提供可以回答的有效问题。 –

+0

@ShaneRay我想浏览加载到文本框和保存按钮单击,将其保存到数据库中的字段,并在需要时检索它 – KAKA

+0

他看起来像他问了一个深远的,但有效的问题“我怎样才能加载文件路径到现场并在我需要时检索它?“尽管充满了语言错误,但我怀疑英语不是这里的第一语言。 – Trey

回答