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.
Related
I am making an app that allows you to open and edit a pdf file on tablets. Because i usually work with .NET, i decided to write it in .NET MAUI. That way i also have access to windows tablets.
It uses Itext as its main library to read and edit the pdf's.
I have an external shared fileserver that anyone can access when they are coneected to the WIFI.
I'd like to access that fileserver when i connect from my android tablet using Itext pdfreader.
How do I achieve this correctly?
Am i missing a library or a package which would allow to me to access that file?
Are there options i haven't discovered yet?
This works on windows tablets:
string dest "\\\\Path\\to\\File\\";
string file = "\\\\Path\\to\\File\\file.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(file), new PdfWriter(dest));
I have tried :
string file = Environment.GetFolderPath(Environment.SpecialFolder.Windows)+ "\\Path\to\File\file.pdf";
string file = "\\\\Path\\to\\File\\file.pdf";
All of them result in file not found
Among the getfolderpath options ive tried a dozen, none of them seem to work.
thank you for your time
So i ended up solving this by transforming the document into a base64 string and sending it through an api that i had.
i used the classic httprequest aproach that you can look up and copy anywhere.
I would like to know to know how to download HTML code from a webpage in Xamarin. The webpage is opened on a Android device and requires login, therefore it cannot be downloaded using a url link in WebClient. I am interested if the is a possibilty to download the HTML code from the opened webside, so that it can be used to notify me about changes in the webside.
My code to open the webside (then i need to log in):
void WebViewFunction()
{
webView1 = FindViewById<WebView>(Resource.Id.webView1);
webView1.Settings.JavaScriptEnabled = true;
webView1.SetWebViewClient(new Client());
webView1.LoadUrl($"https://www.strava.cz/Strava/Stravnik/Prihlaseni");
}
I have absolutely no idea how to do it since I am a beginner.
Thanks for your answer.
I'm trying to download files using a list of urls. how would i go about downloading the files if your urls only end in the page where you would normally click the download button(it has a redirect and wait on the download also)?
i havent actually managed to get further than downloading a file using
but i know this wont work because i wont be able to know the filename and ill have to save it to a file in a config location
using (WebClient client = new WebClient())
{
client.DownloadFile("https://github.com/Hellzbellz123/downloadme/raw/master/TestAddon.7z", "testAddon.7z");
}
I intend to build a backend then plug it into a windows forms app for a gui because im really new to C# and programming in general
Do you mean that you don't know the filenames so you don't know how to save them locally?
If so:
//with 'url' as string
WebClient client = new WebClient();
Uri uri = new Uri(url);
client.DownloadFile(uri, uri.Segments.Last());
It takes the URL and splits it by every slash - the last item in the list is the filename..
EDIT: Improved, thanks to Jimi
That method won't work for links like "[..]/download.php?fileid="
For those links take a look at this
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);
}
I have an app with which at startup it downloads a file from a remote location (through the net) and parses it's contents.
I am trying to speed up the process of startup as the bigger the file gets the slower the app starts.
As a way to speed up the process I thought of getting the last modified date of the file and if it is newer from the file on the user's pc then and only then download it.
I have found many ways to do it online but none of them are in C# (for windows store apps). Does anybody here know of a way of doing this without the need to download the file? If I am to download the file then the process is sped up at all.
My C# code for downloading the file currently is this
const string fileLocation = "link to dropbox";
var uri = new Uri(fileLocation);
var downloader = new BackgroundDownloader();
StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("feedlist.txt",CreationCollisionOption.ReplaceExisting);
DownloadOperation download = downloader.CreateDownload(uri, file);
await download.StartAsync();
If it helps the file is stored in dropbox but if any of you guys have a suggestion for another free file hosting service I am open to suggestions
Generally, you can check the file time by sending HEAD request and parsing/looking HTTP header response for a Last-Modified filed. The remote server should support it and DropBox does not support this feature for direct links (only via API). But DropBox have another feature, the headers have the etag field. You should store it and check in the next request. If it changed - the file has been changed too. You can use this tool to check the remote file headers.