Open Image from solution folder vb.net - vb.net

i need open image from solution folder (the name of the folder is Images)
that image is always copied to that directory, i tried this:
Dim src As String = "../Images/Logos/" & ImageName
Dim MyImage As System.Drawing.Image = System.Drawing.Image.FromFile(src)
But no works, only works if i put all the directory path like: C:/.../ImageName.jpg

Go up two directories... (solution folder\bin\release)
Dim src As String = "..\..\Images\Logos\" & ImageName

I found the answer;
Dim src As String = AppDomain.CurrentDomain.BaseDirectory & "Images\Logos\" & ImageName

Related

How can i get short path from folder directory Vb.Net

i have some path's that i get from folder when i drop in my program but i want to start the path from where the program located.
im putting the program inside the desktop and drag and drop my folder call "Folder" into my program and getting full path and i want get only from where the program is located.
for example:
what i want:
tools\test.exe
tools\test2\test.exe
normal:
C:\Users\xxx\Desktop\Folder\tools\test.exe
C:\Users\xxx\Desktop\Folder\tools\test2\test.exe
my code:
Dim files() As String = e.Data.GetData(DataFormats.FileDrop)
For Each path In files
For Each Dir As String In IO.Directory.GetDirectories(path)
ListBox1.Items.Add(path)
Next
Next
This should work:
Dim relativePath = fullPath.Substring(Application.StartupPath.Length + 1)
The 1 is added to remove the slash that I don't think is included in Application.StartupPath.
Try below line of code:
Dim relpath=System.IO.Directory.GetCurrentDirectory().Replace(System.IO.Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.FullName,"")
This should also work:
Dim relPath = fullPath.Substring(Directory.GetCurrentDirectory.Length + 1)

how do I use a document using debug folder (vb.net)

I am trying to show a document (called zzz.txt so it appears at the bottom) in a text box, and I have put it in the debug folder (TextViewerthingy > obj > Debug) and have used CurDir() & "\zzz.txt" for the location, which apparently is not correct. I have used this correctly with other projects
Dim filename As String = CurDir() & "\zzz.txt"
Dim ObjReader As New System.IO.StreamReader(filename)
gives me an error saying the file is not there. This is the location, what is it that I'm doing wrong in this case?
C:\Users\Notshowingmyname\source\repos\TextViewerthingy\TextViewerthingy\bin\Debug
Try this one :
Imports System.IO
Dim filename as string = Directory.GetCurrentDirectory() + "\zzz.txt"
Or second alternative :
filename = My.Computer.FileSystem.CurrentDirectory + "\zzz.txt"
Make sure file name and extensions are correct.

VB NET - CopyDirectory only copies files? Why?

I have been trying to do this seemingly simple task for a while now, but no luck. Here is some pieces of code I'm using...
Dim SDPath As String = TextBox1.Text
Dim ContentPath As String = TextBox2.Text
Dim RPXName As String = TextBox4.Text
Dim Copy_To_Dir As String = SDPath & RPXName
Dim Copy_To_Dir As String = SDPath & RPXName
'copy any subdirs from ContentDir to SD:\RPXName
For Each ContentDirSub In System.IO.Directory.GetDirectories(ContentPath, "*", IO.SearchOption.AllDirectories)
My.Computer.FileSystem.CopyDirectory(ContentDirSub, Copy_To_Dir, True)
Next
This should create the sub directories in the specific path. Where am I going wrong here??? I've been scouring examples but found nothing. I also want this to copy the contents of the sub directory as well.
Not sure why it isn't working but you could try to make sure that the path you are copying to is a correct directory path. The below code combines the path into a correct path name.
Dim Copy_To_Dir As String = System.IO.Path.Combine(SDPath & RPXName)
You also don't need to write that twice.
Is there any errors appearing?

Screenshot window and save with environment variables

I have code to take a screenshot of a window, seen here:
SC.CaptureWindowToFile(Me.Handle, "c:\Program Files\image_" & Now.ToString("yyyyMMddHHmmss") & ".png", Imaging.ImageFormat.Png)
I want to be able to set an environment variable so that the images will be saved in a folder created by my installer, let's call it "Screenshots" and it's in the Documents folder. I assume I'll have to use something like:
Dim fullPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
But I don't know how to combine these two together so it will save the screenshots into the folder in my documents. Any ideas?
If I understand your question, this should do it:
Dim myDocumentsPath as String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim formattedDateString as String = Date.Now.ToString("yyyyMMddHHmmss")
Dim imagePath as String = String.Format("{0}\Screenshots\image_{1}.png", myDocumentsPath, formattedDateString)
SC.CaptureWindowToFile(Me.Handle, imagePath, Imaging.ImageFormat.Png)

VB.net Return String with Path of folder

My program needs to read an XML file that a software vendor sent me in order to complete a process. The problem is I cannot tell the program where the file is locate!
When i publish the program and install the program it generates a random folder every time it installs
Location the same folder name is always different
C:\Users\Ray\AppData\Local\Apps\2.0\6ZNVVG8V.C6O\0MELQPL9.LCB\lol-..tion_531c8308fa0ff83d_0001.0000_5a2aee0cd0a667c1
I Have figured out how to get that folder to show by doing this
Dim resourcePath As String = _
System.IO.Path.GetFullPath(My.Resources.ResourceManager.BaseName)
Dim rIndex As Integer = resourcePath.LastIndexOf("\")
resourcePath = resourcePath.Substring(0, rIndex)
Dim filePath As String = System.IO.Path.Combine(resourcePath, "Client.xml")
But the program creates a second folder that it puts the XML and the ICOn file in thats randomly generated but in the same directory.
How do I get the program to look in that folder for the xml?
PLEASE HELP ME !
Ray
You could do this:
Dim query = _
From d In System.IO.Directory.GetDirectories(resourcePath)
Let f = New FileInfo(System.IO.Path.Combine(d, "Client.xml"))
Where f.Exists
select f.FullName
Dim filePath = query.FirstOrDefault()
get list of all files by filter
lblPaymentMode.Location = New Point(lblDate.Right - lblPaymentMode.Width, lblPaymentMode.Location.Y)
Dim mFiles() As String = Directory.GetFiles("Path of folder", "*.xml", SearchOption.AllDirectories)
For i As Integer = 0 To mFiles.Count - 1
Debug.Print(mFiles(i)) 'print name and path of of each file
Next