Automatically load XML file from URI using popup download window

ASP.NET MVC 4 Razor:

I have worked a bit on this, so I apologize if I am missing something obvious, but I will really appreciate any help that might be offered.

In short, what I want to do is load an XML file from a URI using C #. This should be pretty simple, but the URI leads to a blank page with a popup loading window populated with a dynamically generated file name.

I cannot provide a URI because of its confidential nature, but here is the code I played with. (Forgive my ignorance in this matter, this is the first time I've tried something like this)

byte[] data; using (WebClient Client = new WebClient()) { data = Client.DownloadData(uriString + fileString); } File.WriteAllBytes(dirString + fileString, data); 

I also tried:

 using (WebClient Client = new WebClient()) { Client.DownloadFile(uriString + fileString, dirString + fileString); } 

Honestly, this code really doesn't work for me. The downloaded files are incorrect. The XML files seem to contain code from the web page from which they were downloaded, and if I try something like an image, the image will be broken. So, again, any help would be appreciated.

Thanks in advance!

+4
source share
1 answer

The URI you are using is probably incorrect. You are using a URI that opens a popup. The popup page should do another GET for the dynamically generated file.

To automate this process, you must use WebRequest to retrieve the contents of the pop-up page. Clear the contents of the page to get the actual URL to download the file. Then use the code you wrote to download the file.

 var request = WebRequest.Create("PopupUrl"); var response = request.GetResponse(); string url = GetUrlFromResponseByRegExOrXMLParsing(); var client = new WebClient(); webClient.DownloadFile(url, filePath); 
0
source

Source: https://habr.com/ru/post/1494281/


All Articles