Downloading a file into Application path - vb.net

so i am using this code to download file
Dim exePath As String = Application.ExecutablePath()
My.Computer.Network.DownloadFile(TextBox2.Text, exePath & "/img.png")
where textbox2 contains url to .png file but i get this error
Note that test.exe is on Desktop.

You can do it in this way
My.Computer.Network.DownloadFile(TextBox2.Text, Environment.CurrentDirectory & "/img.png");
Environment.CurrentDirectory Will give you the current working directory.
I hope this will work for you.

Related

visualbasic cant delete .zip file in a directory

i have three folder in "D:\TestField". These are "backups","ExampleFileUpdatePrimary","ExampleFileUpdateSecondary.zip". I can delete "D:\TestField\ExampleFileUpdatePrimary" folder ,but i cant delete "D:\TestField\ExampleFileUpdateSecondary.zip"
my sub function is ;
Private Sub DeleteFolder(ByVal path As String)
path = path.Remove(path.Length - 1) 'D:\TestField\ExampleFileUpdatePrimary
Dim path2 = path & ".zip" 'D:\TestField\ExampleFileUpdateSecondary.zip
My.Computer.FileSystem.DeleteDirectory(path, FileIO.DeleteDirectoryOption.DeleteAllContents) 'its working
'Dim di = New IO.DirectoryInfo(path2) 'try1
'di.Delete(True)
'IO.Directory.Delete(path2) 'try2
'My.Computer.FileSystem.DeleteDirectory(path2, FileIO.DeleteDirectoryOption.DeleteAllContents) 'try3
End Sub
try1,try2 exceptions says " The directory name is invalid"
try3 exception says "System.IO.DirectoryNotFoundException: ''D:\TestField\ExampleFileUpdateSecondary.zip "
i couldnot find a new solution or try to delete a .zip file in code
thanks
Directory entries ending on .zip are usually files not folders, even though Windows Explorer displays them as folders.
Since they are files, use File.Delete instead.

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.

How to get the full path of a file through the file's name

I am trying to get the path of a file from the name of it. I made an executable file on my desktop, Commands.exe, I am trying to get the full path of it through a console application. I want the program to search the whole of my computer for the file, (it is on my desktop for simplicity) and return the path, bearing in mind the file could be anywhere. The path I want the program to return is:
"C:\Users\Jimbob\Desktop\Commands.exe"
My Code:
Imports System.IO
Module Module1
Dim fileLocation As String
Dim filename As String = "Commands.exe"
Sub Main()
fileLocation = Path.GetFullPath(filename)
Console.WriteLine(fileLocation)
Console.ReadLine()
End Sub
End Module
but instead it prints out
"C:\Users\Jimbob\Documents\Visual Studio 2012\Projects\get path
test\get path test\bin\Debug\Commands.exe"
It prints out the path of the project all of my code is in. In this path, there isn't even a Commands.exe in the Debug folder.
Help?
or couldn't you just
dim fileName as string = My.Application.Info.DirectoryPath() & "\Commands.exe"
You can use the Directory.GetFiles or the FileSystem.GetFiles methods to do this.
Something along the lines of:
fileLocation = My.Computer.FileSystem.GetFiles("C:\",
FileIO.SearchOption.SearchAllSubDirectories,
filename)(0)

Could not find a part of the path during File.Copy

I'm trying to copy a file to another directory but I'm getting this error
System.IO.DirectoryNotFoundException: Could not find a part of the
path 'C:\Documents and
Settings\(my username)\Desktop\Source_Folder\File_1.xlsx'.
But File_1.xlsx exists in the folder Source_Folder which exists on my Desktop. So why am I getting this error?
Here is my code
Dim path_orig As String = "C:\Documents and Settings\(my username)\Desktop\Source_Folder\"
Dim oldFile As String = System.IO.Path.Combine(path_orig, filename)
Dim path_new As String = Server.MapPath("~") & "\Destination_Folder\"
Dim newFile As String = System.IO.Path.Combine(path_new, filename)
File.Copy(oldFile, newFile, True)
*filename is a variable which in this case is "File_1.xlsx"
Don't hard code Documents and Settings. It will change by OS. Use this instead:
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Source_Folder")
Also if you're running this in a web application you're likely running into permissions problems. Change the location where you're storing files and/or change the user the app pool is running under and/or grant the app pool user rights to the folder.

Playing flash file in vb.net

I did some research and come up with this code.
AxShockwaveFlash1.Stop()
AxShockwaveFlash1.Movie = Application.StartupPath & "\RSAppt.swf"
AxShockwaveFlash1.Play()
playBtn.Enabled = False
I don't know why the video is not playing. My RSAppt.swf file is located at a resources(foldername) folder under my project. Is it the path? What is the right way to direct it to the specific path of my .swf file. Any ideas? Thanks!
This should work just fine.
Dim path As String = Application.Startuppath & "\yourfolder\yourfile.swf"
AxShockwaveFlash1.LoadMovie(0, path)
AxShockwaveFlash1.Play()
AxShockwaveFlash1.Loop = False
Happy Coding!!
You need to have:
AxShockwaveFlash1.Show()