Reputation: 35
I want to make an application that can download file from chrome and I just need to download file in chrome not another place or webbrowser control in visual basic so I use below code to download the file:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Process.Start("chrome.exe", "http://zbigz.com/file/1c3d3743dcb8f1d438d71fdc3137e0b79aaa4209/2")
End Sub
and it will be download. but my main problem is that I can't change downloaded file name before downloading . I checked on "Ask where to save each file before downloading" in chrome setting for downloading files and it will pop-up savefiledialog to get the files name and location. I need to know how to fill these feilds.
if someone has another way to change chrome's downloading file name, notice me. Thanks
Upvotes: 0
Views: 2371
Reputation: 626
Try to rewrite the page to have a content.
For now, the page doesn't contain anything but the script.
<?php
$filepath="http://www.internetdownloadmanager.com/pictures/IDM_title.gif";
$filename='IDM_title.gif';
header('Content-Type: image/gif');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=" . $filename);
header("Content-Length: " . filesize($filepath));
readfile($filepath);
?>
<!--A simple html-->
<html>
<header>
<title>Downloading</title>
</header>
<body>
<label>Redirecting to download</label>
</body>
</html>
Rename the file to "index.html" and put it in your "muviz.net/download/" folder, then you will be able to go to the address "http://www.muviz.net/download/" and you will download your file! Hopefully ;)
Upvotes: 0
Reputation: 626
So, if you want to this in PHP you use the following code:
<?php
//Filepath is the full url to your file
$filepath="http://www.example.com/examplefile";
//Filename is the name you want to display for the file, even if the files name is "1" you can set the name to be "2"
$filename='Example Name Here';
//The files description:
$filedescription='This is my example file';
//The first line here contains the filetype of the file, so that it can be open correctly.
//This example is .pdf, but you can use other filetypes - as told later on
//This following "block" contains information about the file
header('Content-Type: application/pdf');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=" . $filename);
header("Content-Description: $filedescription");
header("Content-Length: " . filesize($filepath));
//Download the file
readfile($filepath);
?>
If your file is not a .pdf, go here for a full list of the different filetypes: http://webdesign.about.com/od/multimedia/a/mime-types-by-content-type.htm
So if your file is a .jpg, the code should be;
header('Content-Type: image/jpeg');
instead of;
header('Content-Type: application/pdf');
So... What this script will do is that when it opens from a browser, it gets the file you're trying to download and it changes the information before downloading it. The file could be uploaded to a webserver or (not sure about this) a dropbox account.
VB code should be:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
//The url should be the one to your .php file
Process.Start("chrome.exe", "http://example.com/example.php")
End Sub
I now that this can be quite blurry if you're not used to php and such, but fear not - I will help you! Just comment if there's something wrong ;)
Upvotes: 0