SaveFileDialog Save Button Event - c#

Okay I have this scenario over here. I'm pointing a URL to users to allow them to start the download. The download button has a navigateURL with something like www.mydomainname/files/abc.mp3. So when the user clicks it, it will automatically pop up the SaveFileDialog to allow the user to choose their save destination. My question is, do we have any access to the events of button click in the SaveFileDialog? Like FileOk event?
What I want to achieve is that I want to track the number of times the file is being downloaded. Any pointer would be very much appreciated.

Track File Download hits/count in ASP.Net
Check out the answer to this question. This seems to be a more appropriate approach.

You could check to see if the FileName property is empty. If possible, it might also be worth using sever logs to monitor that if you allow hotlinking as tracking the dialog won't track every possible way to download the file.

As soon as the stream sending the file completes, add a log to the database and that would help you generate reports or do a simple SQL to get back the number of times a song is downloaded.

Related

Handle Upload File Dialog using Selenium for a Material design application

I am trying to automate uploading a file in an Angular/Material design application. Usually, one would just SendKeys to the input box and bypass the browser 'upload file' dialog altogether. But, with Material design, the specific input element isn't available until after a file has been selected. This is the source before the file selection, and this is the source after. I need a way to manipulate the file upload box itself, or at the least enter text into the file selection input of that dialog box and hit enter. I don't know if that's possible using JavaScript Execution, or some other method, but I'm at a loss. Thanks!
I was able to find a solution. Using this documentation, I was able to add a reference to System.Windows.Forms and manually enter the file path/name and hit the enter key. I don't think this solution will work for anything that's not C#, but it worked really well for me.

IE file save/saveas/cancel dialog, is there any way to find out they selected Cancel?

This is C#, asp.net. My page does a response write to a file for downloading. I need to know if the user actually selected open or save because we raise an event to the effect that the person has downloaded the file, whether they did an open or save. But we don't want to raise that event if they hit cancel. Is something like this possible?
No, you can't tell if they pressed Cancel or anything else. That's not an interaction with your web page. Your web page has done its part, providing the response to the user. Now the user is interacting with the browser, telling the browser whether or not they want to accept the download.
To make a comparison: Knowing whether or not they download the file would be similar to knowing what they name the file or what folder they save it in. All of those are behaviors between the user and the browser, not between the user and your application running in the browser.

Add button and custom functionality to adobe reader

I am working on a WPF 4.5 application which needs to interact with PDFs and I am stuck with an issue as described below:
I have template pdfs stored at a specific location. Based on requirement, a copy of the template pdf is created. This pdf has certain fields including text boxes, dropdowns etc. Some of these fields need to be pre-populated like the dropdown values.
Once it is ready, I need to open it, and let the user complete the form. Once completed, the user saves the file and closes it.
Now I need to read the file and send the updated data to the DB. I was able to do all this using iTextSharp by launching the PDF in a separate process and handling the Exited event. Now, the problem I face is this solution does not work if the user uses the SaveAs option to change the name or location of the opened file.
I thought if it would be possible to disable the Save options and add a button on the form clicking which would automatically save the form and close it at the expected location would be a possible solution.
My questions are:
1) Is it possible to find out using the argument of the Exited event handler to find out the saved file name and location? As soon as the user saves the file with a different name, the title of the reader gets updated with the current file name. So I am assuming that the current process is using the latest file.
2) Is it possible to disable the SaveAs and Save file options and close the file on click of a button in the form, using Adobe SDK (JavaScript or plugin or API)?
3) If I use the Adobe SDK, do all the systems on which the application would be installed need to have a licensed version of the Adobe Acrobat?
If the above options are not possible then we would have to settle with dynamic forms. We wanted to experiment with PDF since it is easy to create, and supports image annotations, for which we might need to develop a separate solution, if the above options are not feasible.
I know this is not a very specific programming question, but I need help in order to be able to figure out which path I can go on to be able to achieve the goal.
Please mark duplicate with the link to the other SO question if it a duplicate since I have not been able to figure out one.
Would appreciate answers, links to other posts on SO that are specific to the questions asked.
Please avoid opinion based answers.
Any help would be appreciated.
Any constructive criticism is also welcome.
There is a heavy-handed way to prevent an Acrobat user from Saving a file. In Acrobat, create a Javascript that executes when "Document Will Save." A script like this causes the application to hang rather than Save the file:
var key = "" + this.getField("Password").value;
if (key != "QWERTY") {
app.alert ("No changes to this PDF are allowed,
so you may not Save it.
You will now have to Force Quit or End Task.");
while (true) {};
}
I am not proud of this, but it does the job. You might want to erase the password field before saving.

UploadFile Control loses it's data on PostBacks?

What's wrong! .. seems like it's a common issue .. and even if I try to persist it's value I can only keep it in anywhere like a hiddenfield but looks like there's no property that saves the whole location of the file on the local machine and even if I got it, I can't assign the value back to the FileUpload because all of it's properties are ReadOnly!
Any simple solutions please !?
this is by design - file upload is readonly because otherwise it would be a huge security risk... see http://www.w3.org/TR/html4/interact/forms.html#file-select
depending on what functionality you are trying to implement there could be other possible solutions... please elaborate.
Imagine if you can set that field programatically; what would stop a malicious developer from populating that field and accessing the user's files?
short answer is that every postback will require the user to select the file again for upload. If the postback occurs, it means the file is bad, so the user should be selecting another file anyway.
If the postback occurs because the user entered incorrect metadata for the file, while the file itself is fine, then you can just cache the file name and display it for the user again. Just put a fake, read-only textbox on top of the actual file upload textbox and display the file name back to the user. The file should have already been uploaded to the web server so no upload is necessary (i.e. the real file upload textbox can remain blank)

Accurate way of finding out number of times a file has been download

I have a download page with a linkbutton that users use to download files. The event handler of the linkbutton sets up the Response type for the user to see the download dialog and chose to save it. I need to find out accurately how many times the file has been downloaded. If I increment a counter in the link button's event handler, I'd assume it wouldn't be accurate as the user may chose to click on Cancel in the download dialog.
Where exactly do I need to hook this counter incrementing logic?
You may write a HttpHandler which sends the file.
After the sending has finished then you can increment the number of downloads
Route your file through a 2nd .aspx file that simply reads the real file from disk and echoes it to the page, then when it's done, increment the download counter in your database.

Categories