11 Replies - 910 Views - Last Post: 02 December 2016 - 08:33 PM Rate Topic: -----

#1 Fluddershy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 18-June 16

How would I install a file in a selected directory?

Posted 30 November 2016 - 06:51 PM

Hello, I am wondering how would I install a file in a selected directory. To go into more detail, i'm trying to make the program download a file and put it in a directory. The way I thought you could do it was I could upload it in my resources, and make it be downloaded from there some how. For example: Jimmy clicks a button on the application, the button then starts to install, upload, or download a file(that file is a file I want to select.) Any ideas? I'm not lazy, not at all, I googled and searched but none of the suggested items we're related to my topic, if it is even possible. If you could so kind and share your thoughts and input, and maybe show me a example? Thanks in advance!

This post has been edited by andrewsw: 01 December 2016 - 04:32 AM
Reason for edit:: removed huge text size


Is This A Good Question/Topic? 0
  • +

Replies To: How would I install a file in a selected directory?

#2 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1536
  • View blog
  • Posts: 3,864
  • Joined: 01-February 13

Re: How would I install a file in a selected directory?

Posted 01 December 2016 - 04:27 AM

It is not clear exactly what you mean. If you want your application to download a file and have it placed in a user selected folder, then use a FolderBrowserDialog to let the user select a folder to download it to. Of coarse, you will need some error checking because, the user might select a protected folder that they do not have write permissions for.

After they select a folder, i am assuming that you know the filename for your file, you should use the Path.Combine Method to combine the selected folder path and your known filename.

After you have the full path and filename, you can use that in the second parameter of the WebClient.DownloadFile Method and supply the url location of the file to download in the first parameter. That will download the file into the selected folder.

However, if you mean you want to Install a program in a user selected folder, then set your Installer up to let the user select a folder. I really can`t tell from your question if you want to download a file, install a program, or just write a file from your app`s resources to a selected folder. Maybe a little clearer explanation would help.
Was This Post Helpful? 1
  • +
  • -

#3 Fluddershy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 18-June 16

Re: How would I install a file in a selected directory?

Posted 01 December 2016 - 02:48 PM

View PostIronRazer, on 01 December 2016 - 04:27 AM, said:

It is not clear exactly what you mean. If you want your application to download a file and have it placed in a user selected folder, then use a FolderBrowserDialog to let the user select a folder to download it to. Of coarse, you will need some error checking because, the user might select a protected folder that they do not have write permissions for.

After they select a folder, i am assuming that you know the filename for your file, you should use the Path.Combine Method to combine the selected folder path and your known filename.

After you have the full path and filename, you can use that in the second parameter of the WebClient.DownloadFile Method and supply the url location of the file to download in the first parameter. That will download the file into the selected folder.

However, if you mean you want to Install a program in a user selected folder, then set your Installer up to let the user select a folder. I really can`t tell from your question if you want to download a file, install a program, or just write a file from your app`s resources to a selected folder. Maybe a little clearer explanation would help.

What I mean is I want to install a file from that application. How would I do that? SO Jimmy clicks a button, and a file installs on the desktop that I selected.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15333
  • View blog
  • Posts: 61,458
  • Joined: 12-June 08

Re: How would I install a file in a selected directory?

Posted 01 December 2016 - 02:51 PM

Installs? You mean just downloads to a specific location?
Was This Post Helpful? 0
  • +
  • -

#5 Fluddershy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 18-June 16

Re: How would I install a file in a selected directory?

Posted 01 December 2016 - 03:04 PM

View Postmodi123_1, on 01 December 2016 - 02:51 PM, said:

Installs? You mean just downloads to a specific location?

Yea, I want it to install a file that I want to select. So say I want to install or download a file in a certain directory. For example, I want to download "I_Like_To_Code.jar" in a folder on their desktop. How would I do that?
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15333
  • View blog
  • Posts: 61,458
  • Joined: 12-June 08

Re: How would I install a file in a selected directory?

Posted 01 December 2016 - 03:07 PM

You are using the term 'install' incorrectly and I think that is throwing people off. Installing is a process kicked off to register an app on an OS, put the files in the right program directory, and integrate it to be ran. Downloading file X is not 'installing'.

Have you looked at ironrazor's comment? There is some quality information there to get you started.
Was This Post Helpful? 0
  • +
  • -

#7 Fluddershy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 18-June 16

Re: How would I install a file in a selected directory?

Posted 01 December 2016 - 03:25 PM

I want to install it within the client, because I don't know how to setup a website/pay for a website for just a file.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15333
  • View blog
  • Posts: 61,458
  • Joined: 12-June 08

Re: How would I install a file in a selected directory?

Posted 01 December 2016 - 03:27 PM

*sigh*Okay before I bail on the topic let me try to pry out more information.

What is the client?
Was This Post Helpful? 0
  • +
  • -

#9 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1536
  • View blog
  • Posts: 3,864
  • Joined: 01-February 13

Re: How would I install a file in a selected directory?

Posted 01 December 2016 - 08:30 PM

As modi123_1 has mentioned, your use of the words Install and Download is very confusing because you use them in the wrong context.

If you want to keep a file in your application`s Resources (embedded into the exe file) and have it written to the user`s hard drive when the user clicks a button then you first need to add the file to your applications resources.

Then, it will depend on what type of file it is that will determine what method you need to use to write the file to the hard drive when the user clicks a button. Some files will be stored in the resources as a String such as a (.txt)(.bat)(.ini) Text type file. Some will be stored as a Byte Array such as an (.exe)(.pdf)(.mp3)(MS Word Documents). Others like standard image files (.bmp)(.jpg)(.png) would be stored as Bitmap types.

To write a Text type file from the resources to the hard drive, you could use the File.WriteAllText Method.
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim filename As String = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "My Text File.txt")
        IO.File.WriteAllText(filename, My.Resources.MyTextFile)
    End Sub



To write a file stored as a byte array to the hard drive, you could use the File.WriteAllBytes Method.
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim filename As String = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "My Pdf File.pdf")
        IO.File.WriteAllBytes(filename, My.Resources.MyPdfFile)
    End Sub



To write a standard image type to the hard drive, you can use the Image.Save Method.
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim filename As String = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "My Png Image.png")
        My.Resources.MyPngImage.Save(filename, Imaging.ImageFormat.Png)
    End Sub


Was This Post Helpful? 1
  • +
  • -

#10 Fluddershy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 18-June 16

Re: How would I install a file in a selected directory?

Posted 02 December 2016 - 05:49 PM

View PostIronRazer, on 01 December 2016 - 08:30 PM, said:

As modi123_1 has mentioned, your use of the words Install and Download is very confusing because you use them in the wrong context.

If you want to keep a file in your application`s Resources (embedded into the exe file) and have it written to the user`s hard drive when the user clicks a button then you first need to add the file to your applications resources.

Then, it will depend on what type of file it is that will determine what method you need to use to write the file to the hard drive when the user clicks a button. Some files will be stored in the resources as a String such as a (.txt)(.bat)(.ini) Text type file. Some will be stored as a Byte Array such as an (.exe)(.pdf)(.mp3)(MS Word Documents). Others like standard image files (.bmp)(.jpg)(.png) would be stored as Bitmap types.

To write a Text type file from the resources to the hard drive, you could use the File.WriteAllText Method.
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim filename As String = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "My Text File.txt")
        IO.File.WriteAllText(filename, My.Resources.MyTextFile)
    End Sub



To write a file stored as a byte array to the hard drive, you could use the File.WriteAllBytes Method.
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim filename As String = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "My Pdf File.pdf")
        IO.File.WriteAllBytes(filename, My.Resources.MyPdfFile)
    End Sub



To write a standard image type to the hard drive, you can use the Image.Save Method.
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim filename As String = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "My Png Image.png")
        My.Resources.MyPngImage.Save(filename, Imaging.ImageFormat.Png)
    End Sub


Okay I'm looking at this and It makes a lot of sense, but I have 1 question.
1. Using this method/another method, could I use a .exe or .jar?
This reply was very helpful, and I'll be looking into it more.
Was This Post Helpful? 0
  • +
  • -

#11 Fluddershy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 18-June 16

Re: How would I install a file in a selected directory?

Posted 02 December 2016 - 06:12 PM

Nevermind! I figured it out, thanks to IronRazer! If anyone else had the same question as me, I'll share what I did.

So first of all, I used the code IronRazer gave me, and went to the microsoft page to get more info about it.
I looked into it and I found out you can use other applications when you use "AllBytes." AllBytes meaning it basically copies everything(byes) you put into you're resources.

So, you want to put on whatever you are running the line of text from:
Dim filename As String = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Comboz.exe")
IO.File.WriteAllBytes(filename, My.Resources.TEST)

Once you have that in, you want to rename "Comboz.exe" to whatever you want your file name to be. After you done that you want to drag or upload your file into your Resources in visual basic. So then you want to rename the My.Resources"BLANK" code, the BLANK meaning the file name in your .Resources.

Thank you modi and everyone else to catching onto my horrible description, I tried!

Thank you @IronRazer
Was This Post Helpful? 0
  • +
  • -

#12 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1536
  • View blog
  • Posts: 3,864
  • Joined: 01-February 13

Re: How would I install a file in a selected directory?

Posted 02 December 2016 - 08:33 PM

You`re Welcome. Glad you got it figured out. 8)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1