.net webhandler force download dialog to client c# - c#

I am having a bit of a problem with a web applcation I am developing in .net with C#. I am using a WebHandler that responds to an ajax call from the client, and executes a function that creates a file. What I want is to display download dialog at the end of the file creation process, however the Response class does not exist in the context of the function called by the handler. How to force the application to show the download dialog to the user after file creation? I was thinking about uilding a callback function to the ajax call, and when the execution of the first ajax call returns do another ajax call to a different WebHandler that will force the download dialog. Is this the most efficient way to do this? Is this even correct? What other more orthodox ways can I use to achive what I want? Thank you for yor help.

Consider taking AJAX about of the solution and just redirecting or setting the window.location to the WebHandler url, which will trigger the file download dialog on the browser. Once the user accepts the download, the browser will remain on the page.
Maybe there are more details as to why Ajax is needed. If so, please add them to the question.

On the success operation of your ajax call once the file has been created by the handler just navigate to the file... eihter using C# or JavaScript

Related

How to download infinitely-scrolling web page

With WebClient.DownloadString method it's fairly simple to load normal web page source to string.
But is there any easy way to load those pages which extends and loads new content when you scroll down to end?
You cannot "download" such a page, as it doesn't exist in full form. Such pages require user interaction.
You can use one of the forms of the WebBrowser control to browse to, and programmatically interact with a web site.
hey you can try this approach if you want to do it webclient..
See here.. basically he is using the scrapy but this approach can be adopted in case of webclient to i think so.
basically he is using the firebug or chrome developer tool in order to trace the ajax web request after knowing the web request you can get the content with webclient.

Call a C# function from a button clicked on an HTML page

My application (C#) consists of an embedded web browser which will load a page in HTML from a server. The HTML page will be created from scratch for this particular application. My intention is to have the following procedure:
A user opens the application
A web browser embedded within the application will load an HTML page
User will click a button on the HTML page
A C# function (on client side) is triggered from this action
function does some work
send a list of data back to the web page
Web page will retrieve this data and display it
user's browser will be refreshed to display the new page
Now my questions are the following:
How can a C# function on the client side be triggered when a button is clicked on a server page
What is the best way to transfer data (will probably be object)
how can a function on the HTML page wait for data to be received before continuing to execute the function?
Using the WebBrowser control, you can use the ObjectForScripting property. This will allow JavaScript to call C# code using window.external.C# MethodName
There's some quirks with the serialization you might need to work through, and you might need to use webbrowser.Document.InvokeScript to trigger your data back to JavaScript (I've not personally used the result of a window.external call so cannot speak for it).

Web Scraper via Web Service API?

How would I go about doing the following...
I want to build a web service for my application to grab a piece of data from an external website, that requires the user to login. The website has no public API , hence the reason for the scraper.
Is there a library to perform the following functions? or what do I do?
automate fill-in form, auto click
Automate submit button
check which URL the user has landed
on, and redirect user to URL
Grab data from label.
EDIT: what im asking for is there a web service, library etc to make it easier to perform screen scraping/automation functions???
Instead of filling a form and virtually clicking buttons, you should look at the source of the form, and figure out how the data is being submitted. In most cases you can simply send a post request with the log in data. If there is something special besides a simple post request, I use this addon to figure out what requests are being done that you can't see. Using C#, I would use the HttpWebRequest class because it handles cookies for you.
If the website does not ban robots, you can use YQL to simulate everything you need. However, it can be a bit difficult or impossible as you basically have to implement a text-only browser within JS.

Auto fill web page using ASP.Net C# web page

I need to write a ASP.Net C# web page that can open a web page, fill in the fields and click the submit button on the web page automatically. My web page should launch the IE browser and navigate to a specified URL and fill the form and submit it. Not sure where I should start from. Any help is greatly appreciated.
Thank you.
I'm not sure that, browser will allow to run all your js code.
But you can try with jquery, or with some another javascript lib.
You can add to your page iframe tag, than add dynamically another web-site to the iframe content. You also must know id's or classNames of html controls.
if you're going to use jquery
$(document).ready(function () {
$('#textbox1').val()="someText1";
....
$('#textboxN').val()="someTextN";
//call click event
$('#btnID').click();
});
to automatically start your page, you can use Process.Start() method in server side.
if you're trying too run in client side, you can use Response.Redirect Method
Why not make a POST/GET call directly?
You could use HTTPWebRequest
http://www.codeproject.com/KB/webservices/HttpWebRequest_Response.aspx

File Replace Confirmation

I am developing an ASP.NET 3.5 web application which allows users to upload files to the server. If the user is uploading a file which is already there in the folder then I want to show a ASP.NET AJAX modal popup asking the user whether he wants to replace the existing file or not and continue the operation depending on the user's input. Is there a way to do this?
AFAIK, there is no out-of-the-box functionality to do this. You will have to check for the file existence in code and then display the question.
You don't mention whether you're uploading the file by AJAX or the good'ol fashion way. Since I doubt you'd be asking this question if you were uploading through AJAX (seeing it would be trivial to do this), I have to assume that you're not uploading through AJAX, but that you'd like an AJAX window anyway.
The only way I can think of to do that, is by checking for the file's existence through an AJAX call before you start uploading. This is because when you upload the file, there is no way for the browser to send information back until the upload is complete, and even then you can't use AJAX because the call has to be initiated as an AJAX call as well.
So:
User enters file.
BEFORE sending the file, an AJAX call is made to check whether the file exists
If file exists, ask user, submit form if user wants to replace the file and cancel otherwise.
If file does not exist, submit form.
Hope this helps!
You will need to try the upload using an AJAX call, just sending the filename - the server side method could check for file existence and respond with an error if one exists.
If no error is returned, you can proceed with the upload without the question.
If an error was returned (indicating the file exists), ask the question and follow the users response.

Categories