我有以下代碼將數據從我的計算機上的任何位置上載到名爲Documents
的列中,數據類型爲nvarchar(255)
,SQL Server中的表中作爲文件路徑。上傳,檢索PDF,DOC和圖像到SQL Server
如何在表格中加載到Document
列的文件路徑,並在需要點擊Open
按鈕時檢索它? [見下面的截圖]
我要完成這樣的事情每個記錄
在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);
}
}
毫無疑問這裏。請提供可以回答的有效問題。 –
@ShaneRay我想瀏覽加載到文本框和保存按鈕單擊,將其保存到數據庫中的字段,並在需要時檢索它 – KAKA
他看起來像他問了一個深遠的,但有效的問題「我怎樣才能加載文件路徑到現場並在我需要時檢索它?「儘管充滿了語言錯誤,但我懷疑英語不是這裏的第一語言。 – Trey