Compile ASPX in WinForms App - c#

I'm writing a WinForms application that sends email messages (like a mail merge).
I'd like to use ASP.Net's rendering engine to render the HTML bodies of the messages.
What's the simplest way to get the rendered output of a single ASPX page without the entire ASP.Net runtime?
To make things harder, I'd prefer to compile the ASPX at runtime so that it can be modified without rebuilding the application. However, this is not a requirement; if it's too difficult, I'll give up on it.

Rick Strahl posted an article how to do this at this location: http://www.west-wind.com/presentations/aspnetruntime/aspnetruntime.asp. I know there is a way to call some internal .NET Framework methods but I can't remember what they are off hand.

You may want to consider using a templating lib like NVelocity. Using the WebForms rendering engine in this manner is a bit overkill and hackish at best.
As an aside: keep in mind that HTML in email sucks. Even the most elementary of CSS is ignored by the majority of email clients. If you want my advice, KISS and save your sanity: if you're going to automate emails, send only plain text.

Related

Localize html attribute

I can easily localize any inline text by using
<asp:Localize runat="server" meta:resourcekey="LocalizeResource5" Text="Actions"></asp:Localize>
Is it possible to localize Html attributes directly in aspx code, without using code-behind or other “tricks”? (I mean: supported by Visual studio Resource files generator)
Example:
<input type="text" placeholder="text to localize" />
Thanks
After my experience with localizing quite few websites, I can tell you that ASP.NET localization system is pretty bad (would use some other word here... but must resist the temptation).
You've ran into one problem... for me the bigger problem was changing localized text without forcing user to reload the page.
So, what I would advise you is to ditch ASP.NET localization and switch to something way better, namely Angular-Translate.
Unlike ASP.NET localization system, Angular-Translate has seen WAY much more usage in production and most of the problems you'll run into have already been solved in the library. Plus, you can use it pretty quickly, without much AngularJs knowledge - just see getting started example.

Content Editor for Client

I've created a website for a client of mine. It is coded in ASP.NET with C# and hosted on GoDaddy. She requires this website to updated daily by her. However, this client has very little knowledge of how to edit HTML or text within a site. I don't want to edit it every time she wants an update on the site.
What would be the best solution to my problem? I have looked up Content Management Systems, but I'm a little confused by what exactly it does in terms of coding and the management of the existing site. Does it require me to reformat the whole site to follow the CMS's 'templates'? Would it be better for me design my own back-end panel for her to edit the content (this would obviously take significant work)?
If you want to stick with a site you're developing from scratch, I'd use the HtmlEditor from the AjaxControlToolkit or a similar control, and store the html content in the database.
Then, when outputting the html from the database to the client pages, I'd make sure to use the Microsoft Anti-Cross Site Scripting Library to sanitize the html using the GetHtmlFragment() function (since this is tagged asp.net). It's not that much work, actually, if you design the database correctly, and if you've got the skills.
CMS systems are (trying not to oversimplify) entire web sites that are already built and allow people to edit the content using built-in content editing functionality. They range in functionality and extensibility from a "You get what you get and there's very little you can change" to "You can customize the heck out of it and buy or build your own modules to extend functionality." There are a lot of good ones out there, some free, and some expensive.

Creating a Chatbox with AJAX, HTML and C#?

I am using the Nancy Web Framework in my C# Console Application to basically create a Web Administration panel for my software. I have opted to use the Spark View Engine, as it is basically just HTML. I basically want to create a chatbox, except pull the data written to my application's console every X seconds and display it in a box instead.
I have very little experience with JQuery and AJAX, but they aren't overly complicated from the examples I have seen. The issue I am running into is that ALL of the chatbox and shoutbox examples use PHP.
I basically just need something like this...
The only difference is I need to pull the information from my application instead. I can use basic C# methods inside of the HTML (and probably inside of javascript but I haven't tried this). What would be the best way to do this, and are there any examples floating around that don't use PHP?
This was completed using AJAX and JSON.
Well, to use HTML for styling inside some PC program is just not wise. It has much better UI engines, though. But for your information here is nice jQuery shoutbox tutorial, but well, you only need to handle data input and output with C#, so actually I see no problems. The engine which you are using should have some kind of data stream, or requests handler (bla://program/???)

Web page crawling in C#

I have been given a task to crawl / parse and index available books on many library web page. I usually use HTML Agility Pack and C# to parse web site content. One of them is the following:
http://bibliotek.kristianstad.se/pls/bookit/pkg_www_misc.print_index?in_language_id=en_GB
If you search for a * (all books) it will return many lists of books, paginated by 10 books per page.
Typical web crawlers that I have found fail on this website. I have also tried to write my own crawler, which would go through all links on the page and generate post/get variables to dynamically generate results. I havent been able to do this as well, mostly due to some 404 errors that I get (although I am certain that the links generated are correct).
The site relies on javascript to generate content, and uses a mixed mode of GET and POST variable submission.
I'm going out on a limb, but try observing the JavaScript GETs and POSTs with Fiddler and then you can base your crawling off of those requests. Fiddler has FiddlerCore, which you can put in your own C# project. Using this, you could monitor requests made in the WebBrowser control and then save them for crawling or whatever, later.
Going down the C# JavaScript interpreter route sounds like the 'more correct' way of doing this, but I wager it will be much harder and frought with errors and bugs unless you have the simplest of cases.
Good luck.
FWIW, the C# WebBrowser control is very, very slow. It also doesn't support more than two simultaneous requests.
Using SHDocVw is faster, but is also semaphore limited.
Faster still is using MSHTML. Working code here: https://svn.arachnode.net/svn/arachnodenet/trunk/Renderer/HtmlRenderer.cs Username/Password: Public (doesn't have the request/rendering limitations that the other two have when run out of process...)
This is headless, so none of the controls are rendered. (Faster).
Thanks,
Mike
If you use the WebBrowser control in a Windows Forms application to open the page then you should be able to access the DOM through the HtmlDocument. That would work for the HTML links.
As for the links that are generated through Javascript, you might look at the ObjectForScripting property which should allow you to interface with the HTML page through Javascript. The rest then becomes a Javascript problem, but it should (in theory) be solvable. I haven't tried this so I can't say.
If the site generates content with JavaScript, then you are out of luck. You need a full JavaScript engine usable in C# so that you can actually execute the scripts and capture the output they generate.
Take a look at this question: Embedding JavaScript engine into .NET -- but know that it will take "serious" effort to do what you need.
AbotX does javascript rendering for you. Its not free though.

Working with Dreamweaver and ASP.NET - is this recommended?

I am a ASP.NET 3.5 web developer using VS 2008. I just started at a new company and there are alot of Web Designers here (never worked with Web Designers before). They all use Dreamweaver CS3 and PhotoShop (something i know nothing about).
What I would like to know is the following:
Would they have problems opening my ASP.NET pages in Dreamweaver? ( I heard they might not be able to ).
What about when i use MasterPages? Will they be able to open my pages when i use MasterPages, or must i stay away from MasterPages?
Thanks in advance!
They will be able to work with the markup in your aspx pages, as long as you aern't using complex server controls. Keep the markup fairly simple and you'll be OK. With master pages, they should be able to handle the layout stuff they need, and leave you to worry about the content areas. If you have the opportunity, try to go down a MVC route, this way you are encouraged to keep the code and the markup separate, and the designers will have an easy time seeing your aspx and ascx markup. Designers aren't evil, just different :)

Categories

Resources