Saving contents of <pre> tag to file on server - asp.net

I have searched here and googled for this, and I've probably come across an answer, but I guess I don't understand asp.net enough to get it working. As the title says, I'm trying to save the contents of a tag to a file on the server. I'm specifically using asp.net because I'm developing for a website on a WHS box and I'd like to use the already existing FBA.
Using javascript, I can successfully get the contents, but I am unable to work with it from there. From what I've read, it sounds like I need to POST the contents, either a postback or to another page, to save the file. That's what I'm having problems getting working. I can get a StreamWriter created and working, but I am unable to pass what I need to it.
Thanks for any help, and I can post some of the code I have now if needed. JR

You need to use Javascript to send an AJAX request to an ASHX handler with the text as the POST body.
You can then read the POST in the ASHX handler from the Request object and write it to disk.

Related

How do I submit a form with a large file upload and send ajax requests?

This works in other browsers but not in chrome. I am trying to allow users to upload large files and have an ajax call to update them on the progress of the file upload.
So a unique ID is generated on the client side and added to the action of the form before sending. Then the form is submitted (form only contains a file upload input) and an ajax call is made to get the progress of the upload.
The ajax call goes to another page and uses the ID to lookup the upload.
I am using JQuery 1.5.1. Debugging this and putting something on the error function give me nothing other than "error". Not very helpful. I used Chrome's debugger and it just says failed to load resource xxxx.aspx. xxx.aspx is the URL i needed. Turns out that there seems to be some sort of conflict between the form and the ajax call.
Is there some way to get around this?
you should really look at SWFupload, a great flash based uploader, with concurrent upload and progressbar support. Also it makes it really easy to use server-side, you dont need to implement upload percentage view as it client-side based.
not exactly an answer to your question, but a link to a tool that can really help you drill down and find good error messages, step through javascript code and such would be firebug for Chrome, I got the IE and Chrome versions working and use it very regularly, it has been a life saver and greatly has decreased debugging time:
http://getfirebug.com/releases/lite/chrome/
I would suggest making firebug a common tool in your debugging arsenal.
Use SlickUpload
It is a server control and module that does exactly what you are looking for and takes less than 10 minutes to setup.
Documentation: http://krystalware.com/Products/SlickUpload/Documentation/overview/

<!-- #include virtual="/footer.asp"--> in ASP.NET application

I need to include a header and footer currently located in an asp page. The page takes the language ID and gives you the correct header for the page you are viewing.
I was going thru this: http://forums.asp.net/t/1420472.aspx and this particular fragment seemed to explain it better tho I could not wrap my mind around it.
Hi, instead of using include tags, you could compose your page this way:
Your .NET application here
You can
then implement in codebehind remote
header and footer download logic and
set them in the Literals' Text. After
downloading from the remote site, I
would suggest to store the header and
footer in the application's Cache to
avoid too many connections to the
remote server. If the same
header-and-footer are shared from many
pages in your project, moving this
structure to a MasterPage could be
useful.
Kindly assist.
Well, it would be applicable if header/footer content is coming from some other (remote) server. So the suggested solution is to
Write code to download header/footer content from remote server
Cache the content so that you don't have to download it again and again.
Use literal controls as placeholders on page and set its text to this downloaded content from code-behind.
Now, this may or may not be applicable to your problem. From where does you get the content for header/footer. If its some helper class/method then you can directly call it to set the literal text. You can even do that is master page making things even simpler.
Edit: Additional information requested by OP
You can use WebRequest for downloading content. See this article to get started.: http://www.west-wind.com/presentations/dotnetwebrequest/dotnetwebrequest.htm
Refer below to get started on caching:
http://www.asp.net/general/videos/how-do-i-use-the-aspnet-cache-object-to-cache-application-information
You can use HttpWebRequest to get the required footer text from the asp page and then use the Literal control to display this text.
This page has an example code about how you can submit value to a page and get the response.

Can openx server just xml for a banner instead of adding html?

I want to set up a zone in openx which will be invoked from a flash application, so I want openx to just serve back whatever xml I paste into the 'generic html banner'. Problem is when I use the invocation code for the zone, openx is putting some html around the xml i specified.
Is there a way to get openx to return the xml without adding html around it?
Edit: The same problem occurs no matter what zone type you enter, openx wraps some extra text around it. It appears what I want to achieve cannot currently be done with openx.
After investigating, I have found there is no out of the box way to get openx to return the xml entered without modification.
It might be possible using xml-rpc. However, if this is not a viable option, then you can consider creating a clone of the ajs.php file to only throw out banner content.

iframed ASP actions trouble

This is actually a follow up on my previous question (link)
I've created the HttpHandler and it works fine for now, I'll add flexibility by using the querystring and session to point the post I'm making in the right direction.
The next question is as follows.
Now that I have the old page iframed as it should be, there's still the trouble of handling the postbacks (or actions) these pages trigger.
Every button action (asp form post) refers to a page that is not there (it's on the other server from which I am importing functionality).
I've tried using a url mapping to the other server but I get an error that tells me the external link is not a valid virtual directory. Hence I discarded this option.
I there anyway to keep functionality going inside the iframe?
please do ask clarification if you need it.
I got a solution from a colleague.
before passing the response string to the Iframe from the handler I use a string.replace to adjust the urls in the old site. This way they point to the old site and everything works again :)

Best way to create complex html email message with asp.net, how?

After user places an order I have to send detailed email message containing order details, instructions for payment, some additional text etc.
I want to create nicely formatted HTML email message.
By now I found two options:
manually creating piece by piece, string by string, which is too cumbersome,
creating actual aspx page and binding data, then rendering that page as html and sending as body of email.
This second option is more visual and easier to implement except:
I do not know how to actually load and render page, I know how to do it with ascx
This seems to much of overhead to instantiate page and render it
How to load page and render it? Do you have any other ideas or suggestions for this task?
Well, IMO, your basic problem amounts to "How do I convert an ASPX resource into an HTML string to pass to the MailMessage Body property ?"
You could do that simply by using a WebRequest to the ASPX URL in question and read that response into a Stream. Then simply read the stream into a string and your primary problem is solved.
Edit: Here's an article that illustrates this concept.
Personally, I'd want to use a template, either in a database, or as a file that gets loaded. This template would have most of the content for the email in HTML, with tokens that I can replace with the content.
ex.
<b>Receipt for order # [[ordernum]]</b>
That way I could use simple string replacement to place the dymanic content into the email, without having to build the whole email every time it needs to be sent.
In a similar situation I store a template email message in my database so that the people who use our software can modify the message. It is created (by the user) using the online HTML editor control from Telerik. Within this message, I support several "mailmerge" type fields that all have the pattern {FirstName}, {LastName}, etc.
When it is time to send the message, I pull the formatted text from the database, use string replace to fill in any slots in the template, and then send it. I guess the key is that I know the message is HTML formatted because the Telerik control helps ensure that it is so. However, there is no reason why you couldn't create your HTML and then just save it for later use.
The .aspx page route? I just wouldn't do it. It is way overkill and doesn't offer you any advantages.
I'll use a template like Jay mentioned.
Below resource might turn out useful for you.
http://dotnettricks.com/blogs/roberhinojosablog/archive/2006/05/12/57.aspx
Try using a template stored in a .NET string resource file. Down the line this will make localization a lot easier too.

Resources