Question browse for all pdf file in the directory?

suju_26pro

Well-known member
Joined
May 4, 2011
Messages
48
Programming Experience
Beginner
Hii to every reader, i am new to this site...this my first post , i need a help..

i am creating a application to sign an pdf document..
i am stuck at one place..

i want the user to browse for all pdf file in the directory and display the selected pdf file from a specific folder in a "checklistbox"...he should be able to select multiple file or a specific folder from which all the pdf file must get listed in checklistbox......

plz help me out i am given the screenshot of required ui for better understanding plz have a look ..
waiting eagarly for someone whoo can help me ....
thnx..........
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    62.4 KB · Views: 69
1. You will want to use the FolderBrowserDialog for the user to select both the input & output folders.
2. For your list you will want to use a ListView control with the CheckBoxes property set to True.
3. After the you have the folder path, you will want to use the Directory.GetFiles() method to retrieve the path.
4. Then you will want to use a loop, checking each file name to see if it ends with '.pdf', if it does then add it to the list.

Hope this helps
-Josh
 
1. You will want to use the FolderBrowserDialog for the user to select both the input & output folders.
2. For your list you will want to use a ListView control with the CheckBoxes property set to True.
3. After the you have the folder path, you will want to use the Directory.GetFiles() method to retrieve the path.
4. Then you will want to use a loop, checking each file name to see if it ends with '.pdf', if it does then add it to the list.

Hope this helps
-Josh

Just curious, isn't that what my post suggested?
 
thnx for the hint ....i will work on it ..but my work will be more easy if u provide me the code tooo.........
thnx once again:D
 
Here's a little example:

VB.NET:
'Button: btnInput
'Button: btnOutput
'Button: btnGenerate
'TextBox: txtInput
'TextBox: txtOutput
'ListView: lstFiles (CheckBoxes=True)
'FolderBrowserDialog: FolderBrowser1

'Imports System.IO

Private Sub btnInput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInput.Click
    txtInput.Text = FolderBrowser1.ShowDialog
    If txtInput.Text.Length = 0 Then Exit Sub
    For Each File As String In Directory.GetFiles(txtInput.Text)
        If File.ToLower.EndsWith(".pdf") Then
            lstFiles.Items.Add(File)
        End If
    Next
End Sub

Private Sub btnOutput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOutput.Click
    txtOutput.Text = FolderBrowser1.ShowDialog
End Sub

Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
    If txtOutput.Text.Length = 0 Then Exit Sub
    For i = 0 To lstFiles.Items.Count - 1
        If lstFiles.Items(i).Checked = True Then
            'Add your signing code here
        End If
    Next
End Sub

Hope this helps
-Josh
 
Just curious, isn't that what my post suggested?

Not precisely. As MattP suggested, Directory.GetFiles has an overload that takes a search pattern. For example,

VB.NET:
dim PDFfiles As String() = Directory.GetFiles(txtInput.Text, "*.pdf")
 
OK, I got it :)

Thanks
 
thnx ..i work on this code and do the required changes but i get error.......
wht is the problem....:confused:
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    304 KB · Views: 52
That would imply that the directory 'C:\Users\COD\Desktop\PDF Signer2\PDF Signer\bin\Debug\1' doesn't exist.

On a different note, here is the code snippet with using the Directory.GetFiles Overload:

Private Sub btnInput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInput.Click
    txtInput.Text = FolderBrowser1.ShowDialog
    If txtInput.Text.Length = 0 Then Exit Sub
    For Each File As String In Directory.GetFiles(txtInput.Text, "*.pdf")
        lstFiles.Items.Add(File)
    Next
End Sub
 
And that path exists? There is a folder name '1' in your debug folder?
 
i didn't get u ,4 better underdstanding i just create a demo project using your code...but still it give me the same error......wht to do now...whn i selecte folder for input...it gives me the error...and whn i select the output folder '1' is display in outputtextbox...too confused now plz help me out...my proect subbmission date is comming ..plzz..:confused:
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    286.3 KB · Views: 52
Found the issue, sorry my fault, replace this line:

VB.NET:
txtInput.Text = FolderBrowser1.ShowDialog

With this:

VB.NET:
FolderBrowser1.ShowDialog()
If FolderBrowser1.SelectedPath = "" Then Exit Sub
txtInput.Text = FolderBrowser1.SelectedPath

You will want to change the same with the output folder.
 
thnx a lot ..itz work..but there is an error in your generate button where u told me to put the sign code...here is the ui of it ..wht now..i surf on net a lot..but nt got any valueable answer..seeking a valueable response from u..plz provide code toooo..:confused:
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    301.4 KB · Views: 42
Back
Top