Here is my code to download file using C#
Client.DownloadFile("link","file");
I want to modify it in such a way so that it will create file, only if download is successful. Currently, if I already have a file in the folder where I am trying to download, the above code deletes current file, if download is not successful.
Any suggestions?
Regards,
I see two ways:
Download the file to a temporary name, and when the download is complete you move it to the right place.
Use the DownloadData method to get the data as a byte array instead, and File.WriteAllBytes to save it to the file when you have all the data.
The first option works better for large files, and the second for small files.
Related
I can't seem to find any examples of downloading multiple files from a URL.
I have a URL lets say www.example.com/Document and I want to download all the files in that URL is that possible? or do I need to provide the name of each file in that URL? All the files would download to a folder specified here in the code.
Any examples of this would be great, this would be done by clicking a Download button in WPF.
The way I did this was to create a ZIP file and have all the files in there. You can either pre create a ZIP file and download or you can create the ZIP file as it downloads. I had to write my own software to do that but it does work.
I want to download a single file in a remote Zip file that is in the cloud. The zip file is too large for me to download as a whole therefore I have decided to look for a way to download only a single file(XML) that I need within the archive. I have tried and Tested a webclient and web request but it downloads the whole zip file(also too large file for these technuques usually fails). I'm eyeing the SharpZipLib but I dont know how to use it. Is it the right library I should use or there are other available ones I can get and test. Thank you so much.
I have a zip file and I managed to upload it but I recreate the zip each time I upload. I wanted to know if there is a way to update the previous zip on google drive with the new zip i created. Or do i need to delete the old one and upload the new one?
Yes you can update it. You will need to know the File ID, which you can get from the create response, or by searching for the file with files.find.
Once you have the File ID, you can send an update to it.
All of these operations are explained very well in the docs at https://developers.google.com/drive/v3/reference/files#methods
I am trying to download an exel file using the code but firefox is giving the above mention error.
You need to build a file first, then pass it to you Context.Current.Response.
Here you just write some content directly in the response.
So I'm using WebClient to upload a file to a server. It works great except for one problem. If the file is opened by another program then it will not upload. For instance, if it's a word document that's been saved but is still opened by word then it fails to upload. Is there a way to force it to read whatever is there and upload it?
If i understand your question right then you can use this solution to test if the file is open and then close it if it is. It's a useful helper class i've used in the past.
https://stackoverflow.com/a/1247326/4612655