How to play Telerik RadCaptcha .wav file without open/save dialog - c#

I've got a link on my page allowing the user to listen to a captcha code, clicking the link will show a open/save dialog. If possible, I'd like the browser to just play the file, instead of requiring user interaction.
This is how I return the audio to the browser:
byte[] filebytes = Helper.TextToAudioBytes(code);
Response.AddHeader("Content-Disposition", "attachment; filename=sound.wav");
return File(filebytes, "audio/wav");

You are sending the Content-Disposition header with value attachment. This tells the browser that the file should be saved and not handled as normal content. Removing this will allow the browser to handle the file in a manner based on the browser settings.
Note that the browser settings might still be "save the file" or whatever the user has decided, not necessarily "play the sound".

Related

How to redirect to another page after csv file download?

I have download button which after download i want to redirect to another page.
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=downloadfile.pdf");
Response.TransmitFile(Server.MapPath("downloadfile.pdf"));
Response.AddHeader("Refresh", "3;URL=redirectpage");
This is the code for downloading the file, right now after downloading the file is not redirecting to the page i want to redirect.
Depending on how the request for the file is made, you may want to consider using some client-side code to perform the redirection. A small example of a file download requested from a hyperlink can can be found here:
https://social.msdn.microsoft.com/Forums/sharepoint/en-US/58ff5ed5-c3af-40f9-b136-b0415a0c767c/redirect-after-file-download?forum=sharepointdevelopmentprevious
This example redirects after starting the file download.
You could also redirect then initiate the download as show here (context is with PHP but solution is HTML-based and JS-based)
PHP generate file for download then redirect

Skip "Download file" dialog in WebBrowser control

I submit form in WebBrowser control this way:
WebBrowser1.Document.GetElementById("INS_TASK").InvokeMember("click");
where "INS_TASK" is submit button Id. Form submitted with method POST.
If check traffic by Fiddler there are two requests:
Result 302, method POST
Result 200, method GET
After that "Save file" dialog appears. How to hide this dialog and save downloading file without prompt?
Only the user can decide to save files without prompt.
You can't bypass the save file dialog. This is a browser security feature.
If you could tell the browser to skip the save file dialog then anyone could send malicious .exe files that would be saved directly to disk.

How to force file download on Telerik RadEditor?

I am using Document Manager in Telerik RadEditor.
Once I upload .txt file and click on that link, it opens on the browser instead of downloading it. How to force download that file without going in to .htaccess or other server changes?
Short answer is: using RadEditor alone you can't.
In order to make a browser-viewable file type be served as a download you must send it to the client's browser with a 'Content-Disposition' type of 'attachment'. Doing so is fairly simple, however it requires server-side code that would be outside of the scope of RadEditor.
var bytes = System.IO.File.ReadAllBytes(Server.MapPath("~/path/to/file.txt"));
Response.AddHeader("Content-Type", "text/plain");
Response.AddHeader("Content-Displosition", "attachment;filename=file.txt;size=" + bytes.Length);
Response.Flush();
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
Unless you want to write a specific handler for serving the file in question, your only option is to instruct users that they must 'Right-Click > Save Link As...' on your text file link.

After disabling a Submit button with JS, re-enable after file download

I'm working on an ASP.NET application. Currently when the user clicks "Save" on an item, we disable the Save button, change its text to "Saving..." and so on. This works fine, because the button causes a postback which results in a new page being loaded, on which the Save button is no longer disabled.
We now want to apply this to other actions: Publish (not much different from Save), Import (again, much like Save, but based on data the user has uploaded in a previous step), Export (downloads an XML file to the user) etc.
Export is causing me problems - the button stays disabled. I think this is because the server sends back an XML file rather than a new web page, and so the browser just displays the same page.
The server-side code is along the lines of
Response.Clear();
Response.BufferOutput = true;
Response.ContentType = "text/xml";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + whatever);
[push file contents into Response.OutputStream]
Response.End();
[No idea if this is good code or not - it's not mine - but it does the job :)]
Basically, I'd like to know either:
a way of making the server send a fresh page back in the response as well as the XML, thus re-enablnig the button in the same manner that the other pages do, or
a way of getting the browser/JS to re-enable the button once the file has been sent.
Looks like this should do it: essentially, set a cookie with the file response, and have the browser waiting for that cookie in order to unblock the page.
The problem probably is that you do not load a new page at all.
Since content disposittion is attachement, the browser will not reload the page but only save the return from the server to disk.
You need to reload the page some how but I have no really good idéa on how to do that after a file fetch.
There is a dirty hack. You can use setTimeOut method to enable and change back button caption/image.
So you can write a server side code similar to
btn.Attributes.Add("onclick", "this.disabled='true'; this.value='Processing...';_doPostback(this,null);setTimeout(function() { enable button logic....set the text /img of the button}, );");
The server side download attachment event will not be synch perfectly, but you can set timeout as 2-5 seconds depending on your server configuration.
Thank you!

IE Information Bar, download file...how do I code for this?

I have a web page (asp.net) that compiles a package then redirects the user to the download file via javascript (window.location = ....). This is accompanied by a hard link on the page in case the redirect doesn't work - emulating the download process on many popular sites. When the IE information bar appears at the top due to restricted security settings, and a user clicks on it to download the file, it redirects the user to the page, not the download file, which refreshes the page and removes the hard link.
What is the information bar doing here? Shouldn't it send the user to the location of the redirect? Am I setting something wrong in the headers of the download response, or doing something else wrong to send the file in the first place?
C# Code:
m_context.Response.Buffer = false;
m_context.Response.ContentType = "application/zip";
m_context.Response.AddHeader("Content-Length", fs.Length.ToString());
m_context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}_{1}.zip", downloadPrefix, DateTime.Now.ToString("yyyy-MM-dd_HH-mm")));
//send the file
When a user agrees to download a file using the IE Information Bar, IE reloads the current page, not the page the file the user is trying to download. The difference is that, once the page is reloaded, IE will allow the download script to go through without prompting the user. I'm not sure what the thinking is on this from a design standpoint, but that's how it seems work.

Categories