sql - 如何让用户输入文档然后保存该文档?
问题描述
所以我有点坚持我的项目,我正在使用 Visual Studio 并在 Visual Basic 中编码,如果有帮助的话,我也会使用 Microsoft Access 和 SQL。
我需要的是允许用户从 OpenFileDialog 中选择一个文档,然后将该文档保存到实际程序中,以便下次运行程序时它就在那里。
以下代码是在按下按钮时触发的,到目前为止我所拥有的是......
saveDocumentDialog.Filter = "Document Files|*.docx;*.doc;*.dot;*.txt;*.rtf;*.pdf;*.ppt;*.pptx;*.xls;*.xlsx"
saveDocumentDialog.FileName = "Untitled"
saveDocumentDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop
saveDocumentDialog.ShowDialog()
If saveDocumentDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
fullFilename = saveDocumentDialog.FileName
End If
Using openDocumentDialog As New SaveFileDialog
Dim filename As String = IO.Path.GetFileName(fullFilename)
openDocumentDialog.FileName = "Untitled"
openDocumentDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop
openDocumentDialog.Title = "Select Save Location"
openDocumentDialog.Filter = "All Files (*.*)|*.*"
If openDocumentDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
Try
My.Computer.FileSystem.CopyFile(fullFilename, openDocumentDialog.FileName)
Catch ex As Exception
MessageBox.Show("Could not copy the file." & Environment.NewLine & ex.Message, "Error copying file.", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
解决方案
一种方法是为程序指定一个特定文件夹(例如Public Documents),并将文件保存在那里,并在程序重新启动时从该文件夹重新加载它们。您可以硬编码路径,也可以在程序中进行设置,让用户指定他们喜欢的文件夹。
推荐阅读
- sql - 根据前一行值更新 Closing_Balance
- excel - VBA选择非相邻动态列的范围
- node.js - 具有不同调用者的 bash 别名
- python-imaging-library - 使用 python 在动画 gif 中放置自定义调色板和自定义帧速率
- c++ - 如何在 QT 中的自定义视频小部件 t 上绘制矩形?
- excel - VBA 将数据从一张表传输到另一张表
- sql - 解析 SQL Server 表中的 XML
- c++ - std::make_shared 和受保护/私有构造函数
- java - 使用此代码后我的 Eclipse 崩溃(cpu 100%),任何人都可以确认代码是否有效
- android - 编辑文本上的双向绑定Android