Interact with aspx page to download a file from C# - c#

I'm attempting to automate a task I have of interacting with a website form to download a file.
In human terms, I select a label from a list of options, and then press a submit button. The website then automatically downloads a zip file to the downloads folder.
The actions described above have the net effect of running this code in a browser console:
$('#ListBox1').val($('#ListBox1 option:first')) && $('#Download_0').click()
My question is, how can I download this zip file by running the code from a C# program? Ideally, I would also be able to specify where the file downloads to, although I'm not sure if this is possible.
Please note, this question is not asking how to download a file using C# (see: How to download a file from a website in C# and .net - Downloading a file from a website using C#). No such file exists on the website for me to download. The resulting file is generated and downloaded automatically by the two actions above.
EDIT:
The following code does download a file, however, the file is 24kb (the zip file I'm expecting is around 8mb) and unopenable:
using (WebClient client = new WebClient())
{
client.DownloadFile("https://cdr.ffiec.gov/public/PWS/DownloadBulkData.aspx", AppDomain.CurrentDomain.BaseDirectory + "download.zip");
}
EDIT2:
What I'm attempting to do is download the most recent zip file available containing bulk call report data. The website selects the most recently available data automatically, but I have to manually select the type of file I want to download. As such, the web request won't be static and can't be hard-coded into the program, which is why I'm attempting to interact with the webpage.

Related

Downloading a file from JFrog Artifactory using its URL

I'm using JFrog Artifactory and want to download file using C# and WebClient. The URL is like /filename.zip
But it downloads as a HTML page. Says container is damaged. And also the HTML says "you needs to enable JavaScript".
How can I fix that?
The Retrieve Folder or Repository Archive API allows to download an archive file (supports zip/tar/tar.gz/tgz) containing all the artifacts that reside under the specified path (folder or repository root). However it does not support filtering by properties.
The Artifactory CLI supports concurrently downloading multiple files. It also supports downloading files we matches a set of property values. The CLI, however, will use multiple HTTP requests for doing so.
A third option would be developing a custom user plugin which allows downloading an archive of artifacts matching a set of properties. An execution user plugin can be executed as a REST API call. There is a sample plugin in the JFrogDev GitHub account which can serve as a good start point. This plugin allows downloading the content of a directory as an archive.

Check if the original content of files is not a script or exe content

I am working on file upload and download web App using .net mvc C# APIs and I have read this answer to consider some file security points and I have two questions:
According to the Filetypes point particularly this statement
It's best if the application uses some real content discovery to find
out if the uploaded file is actually an allowed filetype.
I want to check if the user uploads an .exe, .dll or "html containing js code"
file as renamed text file but i don't know how to do that.
According to Content sniffing point, I have added
X-Content-Type-Options: nosniff
To my api web.config file flowing this Answer
but when i upload html page including java script code it uploads and download without any interruption, so how to prevent my app from uploading and downloading these kinds of files.
There are plenty of ideas here (theoretical and practical):
https://security.stackexchange.com/questions/160129/c-malicious-file-upload-to-server
https://www.computerweekly.com/answer/File-upload-security-best-practices-Block-a-malicious-file-upload
I personally would suggest to white-list the extensions that will be allowed to upload, instead of black-listing potentially dangerous extensions.

Upload video to SharePoint library by code

I am making a app for SharePoint and have a form with several inputs for text and for files as well. The input for files works fine for regular files such as Word, Excel, PowerPoint, images etc... but wont work with videos. Is it possible to upload a video to a document library by code? Or cant you do that simply because the files is usually to big and would take long to upload?
The files is of the type HttpPostedFileBase and sent by a normal mvc form.
And this is the code for uploading it to the folder
FileCreationInformation attachFileInfo = new FileCreationInformation();
attachFileInfo.ContentStream = pNewRequest.FileToUpload1.InputStream;
attachFileInfo.Url = Path.GetFileName(pNewRequest.FileToUpload1.FileName);
newFolder.Files.Add(attachFileInfo);
According to this StackExchange answer, SP videos are organized in special VideoSet folders which seem to be similar to doc sets.
You said you're using MVC to submit the files so I'm assuming you're using CSOM on an external server. Here's an example for handling video uploads via CSOM.

How do I redirect to a static HTML page from disk when clicking a link on an ASP.net website?

I was asked to make a downloads page for our company intranet. They want a folder on the server in which they can drop files for others to download. The way I did this was to create an ASP.net website which looks at that folder and creates list of hyperlinks for every file in that folder. Every one of this hyperlinks triggers the function to present that file for download to the user.
Here's the problem. Some of those files are static HTML pages and the users want to navigate to those pages instead of downloading them. So I used the following code
FileInfo file = new FileInfo(pathToFile);
if (file.Extension.Equals(".htm") || file.Extension.Equals(".htmls"))
Response.Redirect("file:///" + file.FullName);
else { /* run the download code */}
The download part works fine. Clicking on an html link does nothing and I can't figure out why.

Background file upload MVC 5

I am uploading large files to server about 4-5 GB. I have currently used HTML 5 and javascript var reader = new FileReader(); to upload the file payload chunk by chunk to the action method and it will write to the file.
Problem with current uploading is if the user navigate to another tab in application or accidentally close the browser, file upload will stop because it's getting chunk using javascript on page. My requirement is also just upload and forget some background task will upload it for you.
I need some background thread that handle the file upload and upload the file in background. Like file upload queue. So if the user navigate to other page the file upload won't stop and continue in background.
Is this possible with web application? I did my research and found that thread is not a good idea on IIS, instead windows service should be used. But don't know how to do this.
I am not a pro so any idea/example will be helpful. Thanks.

Categories

Resources