Is it possible to take a javascript array and SAVE it to a file server-side? - asp-classic

I have a project where Im using a windows hosting environment and classic asp / vbscript and need to take a Javascript array that is created dynamically and save it to a local file ( "somefilename_unique-ID-I-will-add.js" )... I've used fso in the past to create dynamic log files on a couple of projects but am unsure where to begin in terms of figuring out how to take the js array and 'give' it to or access it in .asp / vbscript especially since the .asp runs before any javascript / jquery is run.
Anyone have any idea a) if its do-able and b) how to go about it?
the resulting .js file on the server will be used as the json or jsonp data source for an android and ios app.
Thanks for any light anyone can shed on this.

You can do this.. You would need to create an API method (search for ASP web method) and post the array to the server via an AJAX call. You could then construct the file server side within the web method.
Here is a link for an example of [WebMethod] :
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

If this project is OK with a trip to the server, then you can merely submit a form where the onLoad of the page used JavaScript to fill some hidden form fields with the values from your array. Or even use a querystring, i.e., sender_page.asp?data001=blahblah&data002=blahdeblah&data003=blahdoobleeblah...

Related

Login to asp.net site from another app, then receive filestream

I have an ASP.NET application with pages that use reportviewer. Can someone give me a hint on how to approach the following requirement:
I want to get the report as PDF file from the page, without user interaction. I know I can render the report to a filestream, but since there's no user opening it in a browser, I need to collect the filestream from another application that might run during the night.
There might be other approaches, like a webservice for example that could return the filestream to me, but this would also mean, I have to modify the setup of the datasources that the report receives it's data from. There are a lot of controls on the page, for supplying filter parameters. By using the page life cycle I can use what's already there.
I thought about wget, but haven't tried it yet, and I'm not sure how complicated logging in will be with cookies. I do have full control over the asp.net application though, so if I can modify something there to make it easier, I'd do it.
You can use the "WebClient" in .net application to get the response from the site.
Please refer the below link:
http://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.80).aspx

Using uploadify as part of an asp.net webform?

I have a web form that requires users to fill out some information and upload an image.
What I don't understand:
If I use uploadify to select a file doesn't it upload it right away to the server? Is there a way to defer that until the user would click on a form submit button? Or at least not save it to the file system?
Most examples use a custom HttpHandler for uploading files, but my file upload is part of a form. Should I still use a HttpHandler for that?
Well, I'll try to answer all your many questions, one by one. But before anything, open the official documentation because I will rely on it for answers.
If I use Uploadify to select a file doesn't it upload it right away to the server?
As you can see on the first demo, you can have a anchor (or a button or anything) to trigger the upload start. The Uploadify don't upload nothing until it's done (if the property auto isn't true).
Is there a way to defer that until the user would click on a form submit button?
Like described above, yes. And it's the default way (since the default value of auto is false).
Or at least not save it to the file system?
While the button doesn't trigger the .uploadifyUpload() method, nothing goes to the server. But when the Uploadify starts sending, it will be handled by the server (with the HTTP Handler). The handler is the guy that save it to the file system.
Most examples use a custom HttpHandler for uploading files, but my file upload is part of a form. Should I still use a HttpHandler for that?
As described on the script property, you can point to any server-side language that will handle the HTTP Request containing the data. The HttpHandler is the right thing because it haven't any other processing before or after the code you write. It isn't hard. The official forum shows some samples. And here on StackOverflow we have many questions about it, like these: Getting Uploadify Working in C# and Uploadify not working with ASP.NET WebForms.
The server shouldn't save the file until it is actually actioned by a handler. The Uploadify is providing the UI control for the gathering of the files and feedback. There are some settable properties available to control whether you want the "Auto" upload behavior or not.
You still need some king of server side processing for saving the data and an HTTPHandler is the usual way to do it. The HTTPHandler just operates on what file information it gets from the browser as part of a multi-part form data.
Here is an answer that provides more information about Uploadify: Getting Uploadify Working in C#

How to return ASP as an ActionResult?

In my ASP.NET MVC project I have a requirement to return certain pages in a database-driven way, i.e. the ASP page code is stored in the database, I need to retrieve it and return that.
I tried doing this using a ContentResult, but the problem I'm finding is that all the special characters denoting server-side script are coming through literally and being displayed in the browser.
How do I return an ActionResult that behaves as an ASP page, not as content?
You can't do that. ASP (Active Server Pages) is meant to be interpreted by the web server and only on the server-side. You'd have to write your own client-side ASP interpreter with something like JavaScript to be able to do what you want to do (who knows, maybe that already exists - I haven't looked). But this sounds like a very, very bad idea.

Is there anyway to load up a asp.net page object and render its contents to string from a console application?

I am trying to use aspx pages as an email templates. There will likely be a bunch of objects on the page which will be used as replacements in the html. Because it's an aspx page I'll be able to use databinding, repeaters, etc. At run time, I want to be able to instantiate the aspx page from its path, pass in a bunch of properties, and then get the rendered result of the page and email it. This seems pretty straightforward from a asp.net website (maybe using BuildManager or Server.Execute.) However, I want to be able to use the same templates via a console application by just loading up a page object from its filepath. Is this possible?
You could host your own webserver. Like the Cassini webserver.
In my own application (a Windows-based Desktop-CMS), I include a web server, too (non-Cassini). It works very well, also it does not serve ASP.NET but plain, HTML.
As I did some research back then, I first wanted to use the Cassini, too, but at some point, I found out that too much user privileges were required to run it successfully; this may not be an issue to you, but keeping this in mind and try to run it early with the permissions of the later user, might be a good idea.

How can I know when .aspx call is finished?

I am building a Flex Application that calls a .aspx page on the same webserver which builds a PDF report using SQL Reporting Services. When the report is built it prompts the user to open or save the PDF.
We are trying to find a way to display a Progress Bar to let the user know that the report they requested is being built, and then destroy the Progress Bar once the report is finished being built.
I've tried opening a new window using JavaScript and trying to catch when the window closes, as well as trying XMLHTTPRequest, but nothing to seems to work.
Does anyone have any suggestions?
There are 2 options:
Use the FileReference class in Flex to programmatically invoke your aspx file. You will be able to track the progress of the call from within Flex by listening to its events. But the users can only save the PDF, not open it.
Have an intermediate HTML page that displays a loading icon and then refresh itself to your PDF generating ASPX page. Encode your aspx url along with parameters etc and set it as a parameter to this intermediate page so it knows what to load.
If you don't have control over the page to be able to put JavaScript on it to hit a URL (or call back to the parent/opener), then you might consider whipping up an aspx page of your own to host a ReportViewer control, and display the report inside of that. This would require you to create a .NET website with a page and a web.config - you wouldn't need to do more than make it receive any parameters your report needs, and it would be do-able via inline-to-the-aspx code as opposed to requiring in-depth .NET knowledge.
Or, you could hit the SS-RS API and render the report directly. Here, you'd craft a URL with parameters for the report on the SS-RS API site to accept. I think, though I don't know for sure, that the SS-RS UI uses the API itself behind the scenes. By default the API is hosted in a site called "reportserver" - you might sniff HTTP traffic while the report is being rendered to get you started with the URL that you'd need to hit.
Another option not mentioned here is to create a .Net webservice, add it to your flex project and when it hits the result handler you know the file is created at that point.

Resources