Okay so I have a program that is supposed to download a TXT file which ONLY contains a URL from my Dropbox, save it on my desktop, and then open the webbrowser like Process.Start(DownloadedFile).
My code looks like this:
Dim path As String = "C:\Users\" & SystemInformation.UserName & "\Desktop"
My.Computer.Network.DownloadFile("https://www.dropbox.com/s/uy9jpt1em3o6khp/download_location.txt?dl=1", path + "\" + "Download_Location" + ".txt")
Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText(path + "\Download_Location.txt")
Process.Start(fileReader)
Now my problem is that, the program DOES download my txt file and name it correctly. But even if I know that there is text in the text file, when the program downloads it and saves it on my Desktop named "Download_Location.txt", it is empty. The downloaded file doesn't conatin any text even if Im 100% sure that there should be a URL text.
And when my program reached the code where Process.Start(fileReader) it gives me an error:
You can not start the process because no file name is specified.
Thanks a lot! And sorry for my bad english.
When downloading files via a URL you are required to use a direct URL, due to that you download exactly the URL you specify. The reason you can download it from your web browser is because it first loads the page from the first link, then the page tells the browser to redirect to the actual file.
Direct links through DropBox are accessed via the dl.dropboxusercontent.com website, which is what you'll need to get the direct link to your file. The reason DropBox uses this system is probably because dropbox.com/s/... is yet a bit shorter than dl.dropboxusercontent.com/content_link/...
Having this said, switching your download URL from what you have now to: https://dl.dropboxusercontent.com/content_link/Uxdm1CQxQ50LBm5QejnkGLOIXJf8QL2Iui95XjhMUL2Wz4gjzBwiHttuA07RkbOl/file?dl=1 should work.
Related
I have a WFP app that works well. I open an Access DB and want to do the same with an Excel workbook. Opening the DB is not an issue as I am able to remove the drive letter from the path. I am having a bit of an issue with the search path for the workbook. My path operates as expected when the drive letter is specified [here is the line of code that works properly -- xlWorkBook_AR = xlApp_AR.Workbooks.Open("S:\11_2017_Spring\MPRecords-2\Accounting\FinancialSystem.xlsm")]). When I remove the drive specification from the path it does not operate as expected. I receive an error stating the file is not found. What do I need to do to make this dynamic?
Thanks in advance.
Ed
Try this (if it works for your scenario):
Place the excel file in the same folder as your app (.exe) (I assume this works for your needs).
Use this code to dynamically get the path of your app, and then add on the name of the file, something like the below:
Application.StartupPath & "\FinancialSystem.xlsm"
Supply this to excel's .Open method and I believe it will work.
You will need to import System.Windows.Forms. Read about Application.StartupPath property here: https://msdn.microsoft.com/en-us/library/system.windows.forms.application.startuppath.aspx
I am looking to automate a process at work, which has a step that requires me to go to a website, download data into a csv format, and then do the work and email out. I have written a set of macros that does most of this for me, however, I am having trouble understanding how to download data after navigating to the website (i see a few tutorials where the given website is already in excel format). Basically, you navigate to website, click drop-down menu, and pick export option.
I have the following script currently, and it gets me to the correct page. But I need to click on an "export" button and then an ".csv" format button once I get to this page. Does anyone have any advice, solutions or tutorials that I can look at?
'method to open chrome, collect Jira report and download it to folder
Sub getJiraReport()
Dim chromePath As String
chromePath = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"""
'loads the Jira Page with report
Shell (chromePath & " -url https://companyname.atlassian.net/issues/? filter=10600")
End Sub
Using VS 2013 and vb.
I have a web page and on a button click i would like file explorer to open so the user can navigate to a folder location and highlight a file. The web application will then get the path and filename of the file. Just to be clear I dont want to open the file I just want the details.
I cant seem to find a way of doing this, can you help?
UPDATE
Apologies perhaps I havent explained my self very well.
This is so a user can reference a document saved on a file share with a particular audit (the web page is for recording audits). Therefore they will click a button and file explorer will open. They will navigate to a folder (will be different everytime) and select a file. File explorer will then close and the web application will know the path of the file and its name. I can then use this to create a link on the web page to that document.
For getting directory path use; System.IO.Path.GetDirectoryName(path)
For file name System.IO.Path.GetFileName(path) or System.IO.Path.GetFileNameWithoutExtension(path)
more info is available at http://www.dotnetperls.com/path
Use path.getFullPath() method to get the file path as a string.
If you want to get the file name only use path.getFileName() method.
I'm a beginner in VB, I'm trying to display html page in the webbrowser control.
when I copy the full path of the html file, and put in the url properties of the webbrowser control, everything works. However, when I build the exe file and run it in different computer, the html page can not be displayed.
I know this has to do with the html file path, I'm trying to find a way to display html page using webbrowser control in any computer.
any help will be great guys.
Try:
WebBrowser1.Navigate(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) & "\info.html")
remember to add
Imports System.IO
This is a little late, but better late then never! Sorry I did not find this sooner!
Anyway, instead of adding the file url in the URL property of WebBrowser1, here is what you need to do:
In Form1_Load add the following code:
Dim appPath As String
appPath = Application.StartupPath
WebBrowser1.Navigate(appPath & "/html-file-name-here.html")
Change the "html-file-name-here.html" to what your HTML file name is.
Then when you compile your app, just put your html file in the folder where the app is launching from .
I'm nearly ready to distribute my vb.net application. I have several picturebox files which are loaded currently from c:/temp
I need to change this directory to one that will be OK to use when the user installs it to their PC.
My question is how can I do this? Is there a way to get the installation path, then use that within the code as a variable? eg: myInstalledPath & "/xxx.jpg"
Or... would it be better for me to use mypictures within the mydocuments structure? I'd rather keep all the image files created in a folder which is more hidden from the user (by hidden I mean not cluttering up their own image folders!)
I've tried searching for this, but I seem to get varying results with no real answers... (possibly searching for the wrong thing!)
You can get the ExecutablePath with:
Dim appPath As String = Path.GetDirectoryName(Application.ExecutablePath)
Then you'll know where the application is residing.
As for where to save your images a common location is the AppData folder.
You can get it like this:
Dim appDataPath As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
The AppData folder is by default a hidden folder so that satisfies your requirements.