-
Feb 21st, 2018, 04:21 AM
#1
Thread Starter
New Member
Load, Save & Open Multiple PDF Files with OpenFileDialog
Hello, I need some help for my project.
I have done making a PDF file loader that can be saved into MySql database. All functions go well, but it's only can save and load 1 file.
But now, I need some improvement. How can I choose multiple PDF files to be saved into database, and open it with 1 click? (Example : when there are 2 files, the pdf reader opens in 2 windows at the same time)
The code is here :
Code:
Private Sub Button6_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim kol As String
OpenFileDialog1.Filter = "PDF Files |*.pdf"
OpenFileDialog1.ShowDialog()
kol = OpenFileDialog1.FileName.Replace("\", "\\")
TextBox7.Text = kol
I only retrieve the path (include file name) to TextBox, and save it to database.
When data is called, the path showed in another Textbox, and PDF reader ready to open with 'Process.Start' code.
is my method correct? or is there a more appropriate method?
-
Feb 21st, 2018, 04:54 AM
#2
Re: Load, Save & Open Multiple PDF Files with OpenFileDialog
There's no reason for you to be doubling up the slashes. You only need to escape slashes in literal text, i.e. text written in your code. Also, why do you need a TextBox at all?
Anyway, set the Multiselect property of the dialogue to True and then use the FileNames property instead of FileName. You can loop through it like any other collection.
-
Feb 21st, 2018, 05:41 AM
#3
Thread Starter
New Member
Re: Load, Save & Open Multiple PDF Files with OpenFileDialog
Originally Posted by jmcilhinney
There's no reason for you to be doubling up the slashes. You only need to escape slashes in literal text, i.e. text written in your code. Also, why do you need a TextBox at all?
Anyway, set the Multiselect property of the dialogue to True and then use the FileNames property instead of FileName. You can loop through it like any other collection.
The double slash for replacing the "\" in file path (url address) because it's gonna be written/saved into MySql database, not the PDF file.
My program will be used for recording daily production data (include the PDF), with different Items, date, shift, status, etc.
So, I'm using textbox as a display to retrieve the PDF file of selected Production Items.
Yeah, the Multiselect properties already set to True. But I haven't know the function of 'FileNames' code.
Or.... Is there any method to save/load PDF files directly into database?
-
Feb 21st, 2018, 06:12 AM
#4
Re: Load, Save & Open Multiple PDF Files with OpenFileDialog
Originally Posted by darman3
The double slash for replacing the "\" in file path (url address) because it's gonna be written/saved into MySql database, not the PDF file.
That doesn't matter. Text is text. When you pull it back from the database it's still a String.
Originally Posted by darman3
Or.... Is there any method to save/load PDF files directly into database?
If you want to store the file contents rather than the file path, which would be necessary if you're going to use the data on a different machine, then you can call File.ReadAllBytes to load the data into a Byte array and then save that into the database. You'd need a column of the appropriate data type. I'm not sure what that is in MySQL but it would be varbinary in SQL Server and BLOB in Oracle.
-
Feb 27th, 2018, 02:16 AM
#5
Thread Starter
New Member
Re: Load, Save & Open Multiple PDF Files with OpenFileDialog
Here's the reason I'm using the double slash code.... To call the location of file. Works perfectly.
https://ibb.co/cexMsc
*sorry I can't add image directly
-
Feb 27th, 2018, 05:16 AM
#6
Re: Load, Save & Open Multiple PDF Files with OpenFileDialog
Originally Posted by darman3
Here's the reason I'm using the double slash code.... To call the location of file. Works perfectly.
https://ibb.co/cexMsc
That implies that your method of saving to the database is unsafe, but without seeing your code we can't give specific advice.
Having code to deal with some special characters means that the ones you don't know about (which is far more than you'd think) can also cause problems, and those problems can be far bigger than you think (destroying all the data in your database is one of the smaller ones).
For an explanation of why you should almost certainly be using Parameters (and links to code examples), see the article Why should I use Parameters instead of putting values into my SQL string? from our Database Development FAQs/Tutorials (at the top of the Database Development forum).
*sorry I can't add image directly
To attach images directly, click on "Go Advanced", then "Manage Attachments".
If you attach just one image, it will be automatically displayed in your post.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|