-
1 Attachment(s)
Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox2
Dear all master,
please help I want to change the hard code to the selected path from the browsing dialog folder (I marked yellow in the code below)
and the problem listbox2 is not showing the patch directory. I attached a picture of the problem listbox2.
thanks
roy88
Code:
Public Class Form1
Private FullFilePathName As String = ""
Dim w As Watermarker = New Watermarker("demo", "demo")
Dim twm As TextWatermark = New TextWatermark
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
Using dlg As FolderBrowserDialog = New FolderBrowserDialog()
Dim dr As DialogResult = dlg.ShowDialog(Me)
If dr = DialogResult.OK Then
ListBox2.Items.Clear()
For Each file As String In dlg.SelectedPath
If String.IsNullOrEmpty(FullFilePathName) Then FullFilePathName = System.IO.Path.GetDirectoryName(file)
twm.Text = "Copyright � John Doe, 2008"
twm.Font = New WatermarkFont("Arial", FontStyle.Bold, FontSizeType.Percents, 2)
twm.TextColor = Color.Red
twm.Transparency = 40
twm.Alignment = TextAlignment.Center
twm.Placement = WatermarkPlacement.BottomRight
twm.Margins = New WatermarkMargins(20, 20, 20, 20)
w.AddWatermark(twm)
w.OutputOptions.OutputDirectory = "c:\emp\output"
w.Execute()
ListBox2.Items.Add(file)
Next
End If
End Using
End Sub
End Class
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
Hello,
for the yellow line , you can try
Code:
w.OutputOptions.OutputDirectory =dlg.SelectedPath.tostring
and please don't use anymore yellow color, it is just unreadable with a white background
EDIT : sorry, I misread the code so I removed the first part of my comment
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
Why do you use a listbox? a label or a textbox should be enough as with FolderBrowserDialog you cannot select several folders
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
Quote:
Originally Posted by
Delaney
Hello,
I don't understand really what you want, it seem that textbox2 is the first box and it gives the file list with the path because that's what you code with that
Code:
ListBox2.Items.Add(file)
. and it has nothing to do with the yellow line.
please clarify.
dear sir
my answer 1 : what I mean is listbox2 is the position below and I attach the screenshot file below
so it doesn't match the result unlike listbox1 at the top.
else for the yellow line , you can try
Code:
w.OutputOptions.OutputDirectory =dlg.SelectedPath.tostring
and please don't use anymore yellow color, it is just unreadable with a white background
my answer 2 :according to your additional code it works perfectly and I'm sorry because I marked yellow
-
1 Attachment(s)
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
this is the screenshot file I mean
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
by the way this is of no use, and you choice of variable name is terrible
Code:
For Each file As String In dlg.SelectedPath
selected path is a path not a file and there is only one path
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
Quote:
Originally Posted by
roy88
this is the screenshot file I mean
Yep I figured, the use of the word "file" for a path misguided me. See my previous comments. And use a texbox or a label instead of the listbox.
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
Quote:
Originally Posted by
Delaney
Why do you use a listbox? a label or a textbox should be enough as with FolderBrowserDialog you cannot select several folders
So I want to display a list of directory files that are input in listbox1 and files are output in listbox2 so that in the future I can choose from the listbox to appear in the picturebox
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
if you keep your listbox2, just remove the for each and use
Code:
ListBox2.Items.Add(dlg.SelectedPath)
-
1 Attachment(s)
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
Quote:
Originally Posted by
Delaney
if you keep your listbox2, just remove the for each and use
Code:
ListBox2.Items.Add(dlg.SelectedPath)
dear sir,
Ok. I removed the code "for each" but the results in the listbox do not get the image file name, only the directory. You can see the image file below.
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
You seem to think that the paths of the files in the selected folder will materialise by magic. They won't. If you want the file paths in a folder then you have to get them. One option for doing that is to call Directory.GetFiles.
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
in you code you use "FolderBrowserDialog" so you will get only a path and nothing else. What exactly do you want to get ? a list of files without the path ?
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
Quote:
Originally Posted by
jmcilhinney
You seem to think that the paths of the files in the selected folder will materialise by magic. They won't. If you want the file paths in a folder then you have to get them. One option for doing that is to call Directory.GetFiles.
dear sir
how's the code?
thanks
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
Quote:
Originally Posted by
Delaney
in you code you use "FolderBrowserDialog" so you will get only a path and nothing else. What exactly do you want to get ? a list of files without the path ?
I want the path with the list of files
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
Quote:
Originally Posted by
Delaney
in you code you use "FolderBrowserDialog" so you will get only a path and nothing else. What exactly do you want to get ? a list of files without the path ?
I use FolderBrowserDialog to select the output folder and I want the path with the list of files
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
this will get you all the files (just the name) from a path
Code:
Dim di As New IO.DirectoryInfo(dlg.SelectedPath)
Dim arrayfiles As IO.FileInfo() = di.GetFiles("*.*")
Dim fi As IO.FileInfo
ListBox2.Items.Add(dlg.SelectedPath) ' first i add the path
For Each fi In arrayfiles ' second I add the files
'you can try to put you code here
ListBox2.Items.Add(fi.Name)
Next
PS : .SelectedPath is a string so no need to add .tostring (see post#2), sorry for that
-
1 Attachment(s)
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
Quote:
Originally Posted by
Delaney
this will get you all the files (just the name) from a path
Code:
Dim di As New IO.DirectoryInfo(dlg.SelectedPath)
Dim arrayfiles As IO.FileInfo() = di.GetFiles("*.*")
Dim fi As IO.FileInfo
ListBox2.Items.Add(dlg.SelectedPath) ' first i add the path
For Each fi In arrayfiles ' second I add the files
'you can try to put you code here
ListBox2.Items.Add(fi.Name)
Next
PS : .SelectedPath is a string so no need to add .tostring (see post#2), sorry for that
dear sir,
sorry i'm late reply. I tried with your code it didn't work. The results in the list are also not there and the output image file is also not there.
thanks
Code:
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
Using dlg As FolderBrowserDialog = New FolderBrowserDialog()
Dim dr As DialogResult = dlg.ShowDialog(Me)
If dr = DialogResult.OK Then
Dim di As New IO.DirectoryInfo(dlg.SelectedPath)
Dim arrayfiles As IO.FileInfo() = di.GetFiles("*.*")
Dim fi As IO.FileInfo
ListBox2.Items.Add(dlg.SelectedPath) ' first i add the path
For Each fi In arrayfiles ' second I add the files
twm.Text = "Copyright � John Doe, 2008"
twm.Font = New WatermarkFont("Arial", FontStyle.Bold, FontSizeType.Percents, 2)
twm.TextColor = Color.Red
twm.Transparency = 40
twm.Alignment = TextAlignment.Center
twm.Placement = WatermarkPlacement.BottomRight
twm.Margins = New WatermarkMargins(20, 20, 20, 20)
w.AddWatermark(twm)
w.OutputOptions.OutputDirectory = dlg.SelectedPath.ToString
w.Execute()
ListBox2.Items.Add(fi.Name)
Next
End If
End Using
End Sub
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
As I don't know what this part does or should do :
Code:
twm.Text = "Copyright � John Doe, 2008"
twm.Font = New WatermarkFont("Arial", FontStyle.Bold, FontSizeType.Percents, 2)
twm.TextColor = Color.Red
twm.Transparency = 40
twm.Alignment = TextAlignment.Center
twm.Placement = WatermarkPlacement.BottomRight
twm.Margins = New WatermarkMargins(20, 20, 20, 20)
w.AddWatermark(twm)
w.OutputOptions.OutputDirectory = dlg.SelectedPath.ToString
w.Execute()
I cannot help you more. Sorry.
The code I gave to you in post#16 works (gives the path and the files in the path), I tested it. So they may be some problem with your watermark code. I cannot test your code as I don't have watermark library or functions
-
1 Attachment(s)
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
Quote:
Originally Posted by
Delaney
As I don't know what this part does or should do :
Code:
twm.Text = "Copyright � John Doe, 2008"
twm.Font = New WatermarkFont("Arial", FontStyle.Bold, FontSizeType.Percents, 2)
twm.TextColor = Color.Red
twm.Transparency = 40
twm.Alignment = TextAlignment.Center
twm.Placement = WatermarkPlacement.BottomRight
twm.Margins = New WatermarkMargins(20, 20, 20, 20)
w.AddWatermark(twm)
w.OutputOptions.OutputDirectory = dlg.SelectedPath.ToString
w.Execute()
I cannot help you more. Sorry.
The code I gave to you in post#16 works (gives the path and the files in the path), I tested it. So they may be some problem with your watermark code. I cannot test your code as I don't have watermark library or functions
dear sir,
if I use the code below the output of the watermark works, only the listbox2 problem results. I attach a picture of the listbox2 problem. I can attach the demo library problem if you want.
thanks
Code:
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
Using dlg As FolderBrowserDialog = New FolderBrowserDialog()
Dim dr As DialogResult = dlg.ShowDialog(Me)
If dr = DialogResult.OK Then
For Each file As String In dlg.SelectedPath
twm.Text = "Copyright � John Doe, 2008"
twm.Font = New WatermarkFont("Arial", FontStyle.Bold, FontSizeType.Percents, 2)
twm.TextColor = Color.Red
twm.Transparency = 40
twm.Alignment = TextAlignment.Center
twm.Placement = WatermarkPlacement.BottomRight
twm.Margins = New WatermarkMargins(20, 20, 20, 20)
w.AddWatermark(twm)
w.OutputOptions.OutputDirectory = dlg.SelectedPath.ToString
w.Execute()
ListBox2.Items.Add(dlg.SelectedPath)
'ListBox2.Items.Add(fi.Name)
Next
End If
End Using
End Sub
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
You're just not listening to what you're being told. The SelectedPath of the FolderBrowserDialog is the path of the selected folder. What possible use could it be to add that folder path to the ListBox over and over? If you want to display the file paths then add the file paths. If you want to add the file names then add the file names. DO NOT add the folder path. That's about the third time you've been told that. Maybe you'll actually do it this time.
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
If I wanted to display the file paths in the ListBox, I would do this:
vb.net Code:
Dim folderPath = dlg.SelectedPath
Dim filePaths = Directory.GetFiles()
ListBox2.DataSource = filePaths
That's it. You can then loop over the file paths and process each file:
vb.net Code:
For Each filePath In filePaths
'Use filePath here.
Next
If you want to display the file name rather than the full path:
vb.net Code:
Dim folder = New DirectoryInfo(dlg.SelectedPath)
Dim files = folder.GetFiles()
With ListBox2
.DisplayMember = "Name"
.ValueMember = "FullName"
.DataSource = filePaths
End With
and then:
vb.net Code:
For Each file In files
Dim filePath = file.FullName
'Use filePath here.
Next
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
Quote:
Originally Posted by
jmcilhinney
If I wanted to display the file paths in the ListBox, I would do this:
vb.net Code:
Dim folderPath = dlg.SelectedPath
Dim filePaths = Directory.GetFiles()
ListBox2.DataSource = filePaths
That's it. You can then loop over the file paths and process each file:
vb.net Code:
For Each filePath In filePaths
'Use filePath here.
Next
If you want to display the file name rather than the full path:
vb.net Code:
Dim folder = New DirectoryInfo(dlg.SelectedPath)
Dim files = folder.GetFiles()
With ListBox2
.DisplayMember = "Name"
.ValueMember = "FullName"
.DataSource = filePaths
End With
and then:
vb.net Code:
For Each file In files
Dim filePath = file.FullName
'Use filePath here.
Next
dear sir
there is an error for the first solution
Code:
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
Using dlg As FolderBrowserDialog = New FolderBrowserDialog()
Dim dr As DialogResult = dlg.ShowDialog(Me)
If dr = DialogResult.OK Then
Dim folderPath = dlg.SelectedPath
Dim filePaths = Directory.GetFiles()
ListBox2.DataSource = filePaths
For Each filePath In filePaths
twm.Text = "Copyright � John Doe, 2008"
twm.Font = New WatermarkFont("Arial", FontStyle.Bold, FontSizeType.Percents, 2)
twm.TextColor = Color.Red
twm.Transparency = 40
twm.Alignment = TextAlignment.Center
twm.Placement = WatermarkPlacement.BottomRight
twm.Margins = New WatermarkMargins(20, 20, 20, 20)
w.AddWatermark(twm)
w.OutputOptions.OutputDirectory = folderPath.ToString
w.Execute()
'ListBox2.Items.Add()
'ListBox2.Items.Add()
Next
End If
End Using
End Sub
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
Quote:
Originally Posted by
roy88
dear sir
there is an error for the first solution
Code:
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
Using dlg As FolderBrowserDialog = New FolderBrowserDialog()
Dim dr As DialogResult = dlg.ShowDialog(Me)
If dr = DialogResult.OK Then
Dim folderPath = dlg.SelectedPath
Dim filePaths = Directory.GetFiles()
ListBox2.DataSource = filePaths
For Each filePath In filePaths
twm.Text = "Copyright � John Doe, 2008"
twm.Font = New WatermarkFont("Arial", FontStyle.Bold, FontSizeType.Percents, 2)
twm.TextColor = Color.Red
twm.Transparency = 40
twm.Alignment = TextAlignment.Center
twm.Placement = WatermarkPlacement.BottomRight
twm.Margins = New WatermarkMargins(20, 20, 20, 20)
w.AddWatermark(twm)
w.OutputOptions.OutputDirectory = folderPath.ToString
w.Execute()
'ListBox2.Items.Add()
'ListBox2.Items.Add()
Next
End If
End Using
End Sub
error :Error Overload resolution failed because no accessible 'GetFiles' accepts this number of arguments.
Code:
Dim filePaths = Directory.GetFiles()
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
Sorry, that should be:
vb.net Code:
Dim filePaths = Directory.GetFiles(folderPath)
Of course, you could have figured that out for yourself with a bit of effort. Did you read the documentation for the Directory.GetFiles method? You should have, and it would have told what was expected. You're allowed to think for yourself and you should do so before asking for others' help. That's the way to learn.
-
Re: Change Hard Code To Selected Pach From Folder Browsing Dialog and problem listbox
Quote:
Originally Posted by
jmcilhinney
Sorry, that should be:
vb.net Code:
Dim filePaths = Directory.GetFiles(folderPath)
Of course, you could have figured that out for yourself with a bit of effort. Did you read the documentation for the Directory.GetFiles method? You should have, and it would have told what was expected. You're allowed to think for yourself and you should do so before asking for others' help. That's the way to learn.
dear sir,
I tried your code it didn't work. I made my own code and it worked to appear in listbox2 but the watermarking process didn't work. The solution should be looping as a string. the code below I marked the color that was the problem.
thanks
Code:
Public Class Form1
Dim w As Watermarker = New Watermarker("demo", "demo")
Dim twm As TextWatermark = New TextWatermark
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
Dim result As DialogResult = FolderBrowserDialog1.ShowDialog
If (result = DialogResult.OK) Then
'Show the path using the text box
TextBox1.Text = FolderBrowserDialog1.SelectedPath
'Obtain information about the path
Dim selectedPath As DirectoryInfo = New DirectoryInfo(TextBox1.Text)
'Clear the list box first
ListBox2.Items.Clear()
'Show all the directories using the ListBox control
For Each file As FileInfo In selectedPath.GetFiles
twm.Text = "Copyright � John Doe, 2008"
twm.Font = New WatermarkFont("Arial", FontStyle.Bold, FontSizeType.Percents, 2)
twm.TextColor = Color.Red
twm.Transparency = 40
twm.Alignment = TextAlignment.Center
twm.Placement = WatermarkPlacement.BottomRight
twm.Margins = New WatermarkMargins(20, 20, 20, 20)
w.AddWatermark(twm)
w.OutputOptions.OutputDirectory = TextBox1.Text
w.Execute()
ListBox2.Items.Add(file.Name)
Next
End If
End Sub
End Class