I can't download file from google drive using below mentioned code
string url = https://drive.google.com/uc?export=download&id=XXXX
WebClient client = new WebClient();
client.Credential = new NetworkCredential("XXXX","XXXX");
client.DownloadFile(url,#"D:\\test.xls");
Could you please suggest me to how to download the file using webclient with user credential?
you can download file from google drive using below mentioned Link.
https://developers.google.com/drive/v3/web/manage-downloads
https://www.codeproject.com/Questions/728116/How-to-download-a-file-from-Google-Drive-in-csharp
There is a Quickstart guide for .NET developers in the Drive API docs.
https://developers.google.com/drive/api/v3/quickstart/dotnet
In theory this should work however I am not convinced .NET is well supported. It might be a good idea to try the javascript guide and see how it compares.
Related
Goal: Download documents from a Sharepoint 2010 Document Library using C#
I've searched and found many questions/resources regarding how to download documents to a local disk from a Sharepoint Document Library. I've so far been unable to successfully implement a solution.
For the sake of discussion, my document library is located at the following link:
http://server.domain.com/sites/CompanyLocation/dprtmnts/DepartmentName/MyLibraryName/Forms/AllItems.aspx
Within this document library are two folders, each containing a number of documents. I desire to retrieve a list of these documents (in each folder) and have the ability to download/open a document on command.
Things I've tried:
The linked post from this comment: https://sharepoint.stackexchange.com/a/105923
The linked post (https://stackoverflow.com/a/21056425/2480558) offers a solution for both downloading and uploading. I only need to download, so I tried that. This solution gives me a Microsoft.SharePoint.Client.ServerObjectNullReferenceException. There are no instructions on what the url, listTitle, or listItemId need to be, so I'm probably doing something wrong... it doesn't appear to be getting any files.
I also tried the first blog post on that answer that points to using a package from bendsoft. Apparently that package is a paid package, and it's quite expensive.. I can't go that route.
Another answer: https://stackoverflow.com/a/53733630/2480558
This gives me the following exception: (actual server edited out of exception)
Microsoft.SharePoint.Client.ClientRequestException: 'The IDCRL response header from server 'http://server.domain.com/' is not valid. The response header value is 'NTLM'. The response status code is 'Unauthorized'.
This solution: https://stackoverflow.com/a/15602003/2480558
Honestly, I don't even remember why that one didn't work.
If anyone has something that might help me get on the right path... I'm not familiar with making web requests and web authorization, or anything of that nature.
If you use the example that you found at https://stackoverflow.com/a/53733630/2480558, but you have to adapt it for your local SharePoint server, since that code is logging in to SharePoint Online.
In the public void Connect() definition, replace the line
clientContext.Credentials = new SharePointOnlineCredentials(UserName, securePassword);
with this instead:
clientContext.Credentials = new NetworkCredential(UserName, securePassword, "putYourADDomainNameHere");
I have been tasked with finding a way to save files given a link to someones amazon bucket. These files are attachments uploaded to a ticketing system, and when i used their API to pull the ticket out, i am given a link like the one below(I removed all the private stuff and replaced with XXXXX)
https://s3.amazonaws.com/cdn.XXXXXXX.com/data/helpdesk/attachments/production/36012348362/original/1.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=XXXXXXXXXXXXXXXXXFus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180808T205357Z&X-Amz-Expires=86400&X-Amz-Signature=XXXXXXXXXXXXXX-Amz-SignedHeaders=Host
As you can see, the links time out after 1 day. I am connecting 2 API's together, and i need to be able to upload an actual file into the second API instead of just placing a link that times out after a day. I have tried to use Webclient downloadfileAsync, but all i get is a blank file output. I can go to the link in my browser and do a right click, save image as, so i know its possible, but i havent had any luck programatically. Below is the code snipped i am currently using to try and download it.
using (WebClient wc = new WebClient())
{
wc.DownloadFileAsync(new System.Uri(url), "image.jpg");
}
Any insight or help would be awesome.
Thanks in advance!
I was able to get this working by not using the async version of DownloadFile. Thanks to all the people who helped me resolve this.
I am about to write an App which synchronizes my local folder with the cloud. As far as I know the LiveSDK doesn't provide any method that would help me with that?
So after searching on the internet i found an example here : http://onedrive.github.io/items/move.htm
It is about moving a file, but there is also a name property which should changeable.
So how do I build the Request in C# ?
This is how I tried so far, do not really know how to build the URL, with what parameters and so on. Also, can i make a PATCH-Request with a WebClient?
string url = String.Format("https://apis.live.net/v5.0/" + fileid + "?access_token="+this.liveConnectClient.Session.AccessToken);
using (WebClient wc = new WebClient())
{
//wc.DownloadData(url);
wc.UploadData(url, "PATCH", null);
}
I would be grateful for any clues.
It doesn't look like WebClient can support PATCH requests. You'll likely need to use the HttpWebRequest method (https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.method.aspx) which supports additional verbs. The console on http://dev.onedrive.com should give you a better understanding of how the requests are put together for different calls.
I am developing a Google Drive application for Windows Phone using URLs provided in the SDK through HTTPWebRequest. Is there an API for WP8 to develop Google Drive applications?
I downloaded all of the content without any problem. While I am uploading the MIMEtype, it is not always uploaded correctly, and is uploaded as an octet stream.
Please can anyone help with how to upload to Google Drive using C# code?
Thanks
Check the "Upload Files" section of the Google Drive SDK :
https://developers.google.com/drive/manage-uploads
i got solution, actually i am using string[] HeaderKeys = { "X-Upload-Content-Type" }; string[] HeaderValues = { "application/vnd.google-apps.folder" } for post method,
here i used request.contentType in the place of X-Upload-Content-Type now i am uploading all files with correct stream.
How do I take an image from an url and save it locally?
http://someurl.com/imagename.jpg
-> c:\apppath\imgfolder
ASP.NET C#
I am not very good with IO stuff, hope someone can help me out :)
Try this.
System.Net.WebClient wc = new System.Net.WebClient();
wc.DownloadFile("http://www.domin.com/picture.jpg", #"C:\Temp\picture.jpg");
Since you've tagged this with ASP.NET, it's worth pointing out that if you put this code in your ASP.NET Website/Web Application, you'll need to make sure the the Identity/Account that your application is running as, has permission to write the file to the file system.