I want to show javascript code in my webbrowsers in C#. Normally, When I navigated, browser wants to save it.. But I want browser shows it on browser's screen.. I think that I must do a javascript viewer with webbrowser..
I used like that code but it doesnt work (still asking to save..)
webBrowser1.Navigate("http://xxxx.com/aaa.js", "_mainframe");
Don't use a WebBrowser control for this but simply download it using a HttpClient and display it e.g. in a TextBox.
The WebBrowser control is basically an embedded IE which will download files if it thinks a file with that MIME type should be downloaded or if there are headers like Content-disposition: attachment (which force a download prompt in the browser).
Related
I have a C# WinForms app that runs the WebBrowser control to automatically login, navigate through some pages, and ultimately arrive to page that displays a PDF. I would like to automatically save this PDF whenever I arrive to this page but I have been unable to do this automatically.
Is there a way to automatically click "save" in the webBrowser1.ShowSaveAsDialog() window? Or is there another way to save the PDF that I have successfully displayed in the webbrowser?
Additionally, I have tried to download the PDF using WebClient but this returns a HTML page with failed user/password info. Also, webBrowser1.Document is null so I'm unable to access the document as I would other pages in this routine.
I want to print the web page in asp.net application without using javascript function window.print().
Can anyone tell me a short c# code to achieve my goal?
I do not want to print a document either, my requirement is to print what ever I have on the webpage. The print should be similar to what javascript Window.print() does.
I hope I understand your question, it sounds like you want to print a web page (HTML) using C# code.
I've used wkhtmltopdf before (http://wkhtmltopdf.org/) and on the same site, there's wkhtmltoimage. The utility runs as a command line tool, so it's easy to use in C#. After you have the image or PDF file (I'd opt for the image version), it should be easy to print out.
Your biggest concern is rendering the HTML into a page, that is what wkhtmltopdf/image does for you.
You're asking for a lot there. Printing is something the client (the web browser) has to do. The window.print() function tells the browser to print the page, and if you can't use javascript, then you have to '' the page on the server. If you want to print the page on the server side, then you have to take the HTML and convert it to some printable format like PDFs or rendered pictures.
Try out selenium webdriver. You can get a headless browser like PhantomJS (running on the server) to 'screen capture' the page to a PNG. Then you can send that to the browser. Unfortunately, selenium web driver does not support PDF 'screenshots'.
There's also a nuget package for selenium if you're into that sort of thing.
Hi all I have this problem.
I need to open a webpage in chrome and copy the content (the page displays only 1 line of text, no images or anything)
Page source would be ok(it's the same thing).
My c# software is able to generate that link and to open it in chrome (it's important not to use webforms or IE)
But then I would need to "get" the text displayed by chrome and use it in my software again.
I hope it's clear:
my sofwtare generates a link containing needed text--->open link in chrome-->get text content or page source--->elaborate it inside my c# sofware again (maybe copy it to a string or so)
I'm a newbie. Sorry guys.
I am working on a video upload module, which ultimately stores all the user uploaded video's on the youtube (using youtube api's).
I want to display a progress bar as soon as user click's on upload button and continue showing until the video is uploaded.
I know generally this is achieved using ajax toolkit in .net but since I am using File Upload control, its not compatible with the ajax toolkit.
Kindly suggest me how I achieve this.
You can not show the actual progress of the file upload. But you can show a hidden animated "loading" image with javascript. It will show while the form is submitted (with the file) to the server.
Html:
<img id="loading_img" style="Display: None" src="loading.gif" />
Javascript:
$('#Form1').submit(function() {
$('#loading_img').show(); // Show image
return true; // Proceed with postback
});
A while ago I needed exaclty that, I first did search for a javascript solution but ended up with a Flash uploader. Some browsers (Chrome, Firefox) report uploading status if you're uploading through the XMLHttpRequest API in Javascript, so it definitely can be done, but this method is (or was at the time I checked it out) not cross-browser.
You can check this example and also this Q & A.
If that doesn't work cross-browser, you can use an existing Flash file uploader or create one your own using Flash or Silverlight. This, of course, makes your site Flash or Silverlight dependent.
This, for example, is a project that uses Flash.
Fastest way to do that is to buy 3rd party control, for example Telerik Upload control can do that (no flash)
http://demos.telerik.com/aspnet-ajax/upload/examples/customizingraduploadui/defaultcs.aspx
Is there a way to write PDF to a div from DataBase i.e. Retrieve a Byte[] from Database and Reponse.BinaryWrite to a div.
We do similar thing for Images using src = "anotherpage.aspx" where image is written on anotherpage.
Is it possible with PDF without using IFrame?
If what you're trying to do is show a PDF file inside a DIV, you're going down the wrong path. You either need to:
Convert the PDF to Flash (ala Flash Paper)
or
Convert the PDF to HTML (like Scribd does using HTML 5).
Then you can embed the PDF inside a DIV. But no browser I know of supports directly embedding PDFs.
Otherwise you have to put the PDF in an IFRAME, but how this is shown is PDF plug-in dependent.
No. The reason it works with a src=otherpage.aspx request is that the src attribute results in the user's web browser making a completely separate request for the other resource. You're serving up an additional page to make that happen. Writing a PDF file directly is trying to inject the PDF into the same request as your page - not really "similar" to your img src at all. In fact, what is most similar to the "src=otherpage.aspx" method is the iframe approach that you mentioned.
As a side note, you our "AnotherPage.aspx" example should really be changed to "AnotherPage.ashx". Note the letter 'h' in there. That means you're using a handler rather than a page, which will perform better.