Trying to download file in code.
How to download files from Sharepoint document library using ssis? How do you download a file from a document library in sharepoint to local folder? Open a File in document library of sharepoint. Under the covers WebClient uses System.Net.HttpWebRequest for HTTP traffic. I have used HttpWebRequest to download 30 MB files before and it worked great. Similarly, you can use FileWebRequest for files on the local machine or on a share and FtpWebRequest for FTP downloads. Hope this helps. BTW, what happens when you use WebClient.DownloadFile()?
Current code:
Q See Webclient Download File
Running this code and checking the response.ResponseUri indicates im being redirected back to the login page and not to the pdf file.
For some reason its not authorising access what could I be missing as Im sending the user name and password in the uri? Thanks for your help
3 Answers
You don't need all of that code to download a file from the netjust use the WebClient class and its DownloadFile method
WaleedWaleedyou should check and see if the site requires cookies (most do), i'd use a packet analyzer and run your code and see exactly what the server is returning. use fiddler or http analyzer to log packets
With UWP, this has become a more pertinent question as UWP does not have a WebClient
. The correct answer to this question is if you are being re-directed to the login page, then there must be an issue with your credentials OR the setting (or lack of) header for the HttpWebRequest
.
According to Microsoft, the request for downloading is sent with the call to GetResponse()
on the HttpWebRequest
, therefore the downloaded file SHOULD be in the stream in the response (returned by the GetResponse()
call mentioned above).