how to save posts content in asp.net - asp.net

I am looking for advice on how the save long post contents in asp.net. What i mean is that i have a personal website (blog alike) in which i write some code snippets and tutorials. every post got header, tag, date and the content itself. right now i am saving all in mssql table but i am not sure this is the right way to do it, because the content of the post can get very long and i know that sql has a limit of 4000 chars (im using nvarchar as the type of the column). so i thought about saving the post content as usercontrol(.ascx) but from searching it looks too much complicated to create usercontrol on the fly and save it as a file.
so i need your advice on this.

You can use NVARCHAR(MAX) in SQL which removes the limit.

You might look at a "Document Database" such as RavenDB.

Related

How to insert html not from database and not using the iframe?

I wish basically to store my pages or product long descriptions in txt or html files in folders, not in database.
Is there any simple and easy way to do so, instead of iframe which does not work quite well and does not even display the content in the page code so it is not indexed by search engines as it should.
I've read about web components html imports but that seem to be so much complicated and does not really satisfy my needs.
I have not found any plugin to do so, maybe there is one.
I know I wish to make wordpress flat file cms, but maybe there is some new easy way to simply insert pages from anywhere but database might be via shortcode or just an url.
I put it in tags, should say more clear, it is about wordpress on host. As it stores all pages and data in database and I realized bigger database is slower it works. I use caching plugin but I also wish to speed up admin panel and dynamic uncacheble content. My idea is to slim down the database as much as possible and in my woocommerce store most of the data is long description. So the best way would be to inject the long description via shortcode that would take html content from anywhere else but database. I need html, not just some text to insert. This way I would cache these product pages anyway but the database would stay way slimmer and all the dynamic content would go way faster.
In PHP you can use the function file_get_contents, which will display the contents of a file (but not parse it as PHP, which is more secure for obvious reasons).
So you could try something like this if you wanted to account for a page not found message:
function example_get_content($file_url){
if(file_exists($file_url)){
return file_get_contents($file_url);
}
else{
return 'Sorry, this page could not be found'
}
}
And then in your template use
echo example_get_content('http://example.com/my_text_file.txt');

WordPress - add Database driven tables

I'm just trying to move one of my old php sites to wordpress. As part of the site I have 'top tables' e.g. top 10 cars, listing their features etc. At the moment that all comes from a database and the HTML is generated from the data.
So if a car soon gets a hybrid engine I just check that in the database and my web site table updates to reflect that.
This all works fine. I just don't know where to start when trying to implement something like this in wordpress. I want to keep the WP header, footer, nav... and put my table in to the content area.
Someone recommended simply copying the current generated HTML in to a new post and editing the HTML when anything changes, this sounds like a quick solution but there must be a better way of doing this.
Ideally I would want to keep my current data input pages (and separate database) for all of this 'table data' and present the out put as a post.
If anyone can point me in the right direction (key words I should search for, a guide) that would be great.
Depending on your usecase, you'll usually want to use a static page template:
http://codex.wordpress.org/Page_Templates
Or shortcodes:
http://codex.wordpress.org/Shortcode_API

Editing a Drupal page for someone. Using Unfiltered HTML, Drupal is backslash escaping quotation marks that I'm using in image tags. What gives?

I know nothing about Drupal, but I'm helping someone out with editing a Drupal page they're working on for a conference.
One of the things I did for them was auto-generate a table based on some pictures and data scraped from a CSV file I was provided. A typical row in the table looks something like this:
<tr>
<td>
<img src="http://external.host/pics/pic.jpg" height="100" style="height:100;" />
</td>
<td>
<h3>Name</h3><p>Organization<br />Country of Origin</p>
</td>
</tr>
The problem is, even using completely unfiltered HTML (the configuration for the content type has absolutely nothing checked off), after saving the table, Drupal is escaping all of the quote inside the image tag.
This breaks the tag, and I get a bunch of broken images.
What am I missing?
Edit: Drupal 7
The fix for me was to turn off magic quotes in php.ini, thinking something changed on the hosting side as this setting has been on for the last 3 years.
magic_quotes_gpc = Off
Same problem here and turning magic_quotes_gpc helped, but I needed to do it in the php.ini file, setting it off in the .htaccess, as Drupal does by default, does not necessarily help, depending on the PHP configuration.
See http://drupal.org/node/1437998 for more info.
Are your views showing nodes or fields? If nodes, are you referring to the teaser or the full node?
Views with Fields do not retain the same formatting or HTML/CSS structure as full content (nodes). Your view can return a list of content or teasers which will display the same as the content page. Otherwise, you will need write CSS specific to the fields views that you create.
ANSWER EDITED
I cannot definitively state why this is happening, but as Maya stated and my initial suspicion was leaning, this is most likely the result of some sort of backend database entry sanitization.
I was, however, able to find a workaround. Simply use unquoted attributes. Although it is not considered good practice, and it's certainly ugly to read, it's the only thing I was able to do to keep Drupal from escaping the quotes with backslashes and breaking my markup.
had the exact same problem -- just started today. I finally had to update the node in the database just to get it updated.
I think the question is a little unclear. Where did you put the info of the CSV file. In a separate table? Inside the body field of a node? Also, how did you import the data? And more importantly how and where are you printing that data?
Anyways, You could just create a new table and print the information in the tpl of the file.
Or, you could install the php field format and print it yourself directly from php.

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.

Parsing PlainText Emails from HTML Content (ASP.NET)

Right, in short we basically already have a system in place where the HTML content for emails is generated. It's not perfect, but it works.
From this, we need to be able to derive a plaintext alternative for the email. I was thinking of instantly jumping on and creating a RegEx to strip the <*> tags from the message - but then I realised this would be no good because we do need some of the formatting information (paragraphs, line breaks, images etc).
NOTE: I am OK with actually sending the mail and setting up alternative views etc, this is only about getting plaintext from HTML.
So, I am pondering some ideas. Will post one as an answer to see what you guys think, but thought I would open it up to the floor. :)
If you need any more clarification then please shout.
Many thanks,
Rob
My Solution
OK, so here it is! I thought up a solution to my problem and it works like a charm!
Now, here are some of the goals I wanted to set out:
All the content for the emails should remain in the ASPX pages (as the HTML content currently does).
I didn't want the client code to do anything more other than say "SendMail("PageX.aspx")".
I didn't want to write too much code.
I wanted to keep the code as semantically correct as possible (no REALLY crazy-ass hacks!).
The Process
So, this is what I ended up doing:
Go to the master page for the email messages. Create an ASP.NET MultiView Control. This control would have two views - HTML and PlainText.
Within each view, I added content placeholders for the actual content.
I then grabbed all the existing ASPX code (such as header and footer) and stuck it in the HTML View. All of it, DocType and everything. This does cause VS to whinge a little bit. Ignore It.
I then of course added new content to the PlainText view to best replicate the HTML view in a PlainText environment.
I then added some code to the Master Page_Load, checking for the QueryString parameter "type" which could be either "html" or "text". It falls over to "text" if none present. Dependant on the value, it switches the view.
I then go to the content pages and add new placeholders for the PlainText equivalents and add text as required.
To make my life easier, I then overloaded my SendMail method to get the response for the required page, passing "type=html" and "type=text" and creating AlternateView's as appropriate.
In Summary
So, in short:
The Views seperate the actual "views" of the content (HTML and Text).
A master page auto switches the view based on a QueryString.
Content pages are responsible for how their views look.
Job done!
If any of this is unclear then please shout. I would like to create blog post on this at some point in more detail.
My Idea
Create a page based on the HTML content and traverse the control tree. You can then pick the text from the controls and handle different controls as required (e.g. use ALT text for images, "_____" for HR etc).
You could ensure the HTML mail is in XHTML format so you can parse it easily using the standard XML tools, then create your own DOM serialiser that outputs plain text. It'd still be a lot of work to cover general XHTML, but for a limited subset you plan to use in e-mail it could work.
Alternatively, if you don't mind shelling out to another program, you could just use the -dump switch to the lynx web browser.

Resources