Trying to automate file downloads, using Watin in IE. Have a 10 documents to be downloaded and i could find that the below code will prompt for download option.
string download_url="link to file";
browser.Goto(download_url);
I would like to automatically save these files into a new directory with custom names for each files. Is it possible without user prompt for saving files in IE(vesrion 8 and above). Please guide me with a solution for this issue.
From your question I can find several other responses right here. Like this one:
Downloading a file with Watin in IE9
using(IE ie = new IE(someUrlToGoTo))
{
FileDownloadHandler fileDownloadHandler = new FileDownloadHandler(fullFileName);
ie.AddDialogHandler(fileDownloadHandler);
ie.Link("startDownloadLinkId").ClickNoWait();
fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(15);
fileDownloadHandler.WaitUntilDownloadCompleted(200);
}
Related
So I've been trying to download a file from MediaFire using WebClient.DownloadFile(), but all files I download do not work properly. I've tried to download PDF files and PNG files, none of them open correctly in their respective software. I'm using this for a WinForms desktop application. I've already searched for multiple solutions but none of them apply to my situation.
This is the code I've used:
private void downloadFile(string url, string filename)
{
var client = new WebClient();
client.DownloadFile(url, filename);
}
I'm a begginer so any help is appreciated!
I found the solution myself with some help from Jimi.
I needed to find the link the page was using for the download process, not the link to the page itself. I did this by accessing the code of the page using the inspect tool and finding the direct link to the file, then using my previous method it worked just fine.
Do not mark question as "Duplicate", please, because it's not.
I'm asking about creating Chrome profile, not about opening them, please help.
This question asking how to create Chrome profiles programmatically using C# for further using it in selenium (prefer a way using selenium\chromedriver if it's possible).
I need to create one chrome profile for each login in logins[] array (Alex, Lucas, Josh).
//some way to create chrome profiles.
foreach(string login in logins){
options.AddArguments("--user-data-dir=" + pathToProfiles + login); //using created profile
using (IWebDriver webDriver = new ChromeDriver(options))
{
webDriver.Navigate().GoToUrl(#"https://www.facebook.com"); // or any other website.
}
}
The way of creating chrome profiles manually not fit in my case.
I found article with almost same issue, but for Firefox: Creating Firefox profile and switching off the marionette
I can create new profile in Chrome with name "template" and when I need to create new one, just copy paste "template" and rename folder to "Alex".
But I'm searching for normal way to solve it.
Maybe ChromeDriver has function to create profile?
options.AddArguments("--user-data-dir=" + pathToProfiles + login);
This method can create a new profile but it may fail because of the permissions on the profiles folder.
So changing the path to a app path can create the profile successfully
options.AddArguments("--user-data-dir=" + "c:\myapp\"+ login);
When using the below code to try to open File Explorer to a folder path I get the errors SEC7134: Resource 'file://...' not allowed to load, and SCRIPT70: Permission denied.
However if I copy the exact path returned in the error and past it into the url it opens a new file explorer window without any issues. This was working at one time for me as expected, I'm wondering if there have been security changes or things that need to be updated on my side to open these files in File Explorer again.
Thanks,
function openFile(path) {
// Internet Explorer 6-11
var isIE = /*#cc_on!#*/false || !!document.documentMode;
// Edge 20+
var isEdge = !isIE && !!window.StyleMedia;
if (isIE || isEdge) {
window.location.href = path;
return false;
}
}
Yes, we could use the browser as file explorer to retrieve the files in our local environment. But, reading local files from the browser (using JavaScript) is not allowed. This will prevent websites reading files and stealing your information.
If you want to display the local file using JavaScript, you could use the upload control select the local file, then, read the file and display it.
I use ASP.NET and C# to create file content from binary value
FileStruct currentFile = null;
File file = new File();
currentFile = file.GetFile(FileID, strTableCode);
Response.ContentType = currentFile.ContentType;
Response.OutputStream.Write(currentFile.FileContent, 0, currentFile.FileContent.Length);
Response.AddHeader("content-disposition", string.Format(#"attachment;filename=""{0}""", currentFile.FileName));
Response.Flush();
I put this content in an iframe with jquery.
After this an open/save dialog is shown.
How can I force to open the file directly without open/save dialog?
You can't not really anyway.
The way the browser handles the upload is completely up to the browser. (and or user settings)
If you had complete control of client machines there probably would be some browser settings you could force that would open new downloads.
If you had some extra certainties like the browser would always be X you could check out information for a specific browser or write a simple add-on to open files from a certain server. Add that information to you're question.
you cannot force open a file on client machine afterdownload, max you can do is open a new window with something like Response.Redirect("/somePDFFile.pdf"), where somePDFFile.pdf is file on server which client just downloaded
i have an asp hyperlink i want to link it to a .doc file found on a shared folder.
i was able to do this in internet explorer but not in firefox:
my code:
hlc.NavigateUrl = #"file:\\direct\upload\file.doc";
Might want to use forwardslashes (as per convention)
hlc.NavigateUrl = #"file:///direct/upload/file.doc";