paste news article from word and save in dbhttp://forums.asp.net/t/1792462.aspx/1?paste+news+article+from+word+and+save+in+dbThu, 19 Apr 2012 14:02:12 -040017924624930527http://forums.asp.net/p/1792462/4930527.aspx/1?paste+news+article+from+word+and+save+in+dbpaste news article from word and save in db I have news articles that get written in MS Word and I want to be able to insert these into the db to be displayed on my website. What would be the best way of doing this and how would I keep line breaks ect? Thanks 2012-04-13T07:18:17-04:004930941http://forums.asp.net/p/1792462/4930941.aspx/1?Re+paste+news+article+from+word+and+save+in+dbRe: paste news article from word and save in db <p>you can read more here : <a href="http://www.asp.net/web-pages/tutorials/data/5-working-with-data"> http://www.asp.net/web-pages/tutorials/data/5-working-with-data</a>&nbsp;and&nbsp;could use this code to enter news articles into the db :</p> <pre class="prettyprint">@{ Layout = &quot;&quot;; Page.Title = &quot;&quot;; var db = Database.Open(&quot;dbname&quot;); var Title = Request[&quot;Title&quot;]; var Content = Request[&quot;Content&quot;]; var Date = Request[&quot;Date&quot;]; if (IsPost) { var insertQuery = &quot;INSERT INTO newsarticles (Title, Content, Date) &quot; &#43; &quot;VALUES (@0, @1, @2)&quot;; db.Execute(insertQuery, Title, Content, Date); } } &lt;h2&gt;Add news Articles&lt;/h2&gt; &lt;form method=&quot;post&quot; action=&quot;&quot;&gt; &lt;div&gt; &lt;p&gt;Date: &lt;input name=&quot;Date&quot; type=&quot;text&quot; size=&quot;30&quot; value=&quot;@Date&quot; /&gt; &lt;/p&gt; &lt;p&gt;Title: &lt;textarea name=&quot;Title&quot; rows=&quot;3&quot; cols=&quot;74&quot;&gt;@Title&lt;/textarea&gt; &lt;/p&gt; &lt;p&gt; Content: &lt;textarea name=&quot;Content&quot; rows=&quot;14&quot; cols=&quot;74&quot;&gt;@Content&lt;/textarea&gt; &lt;/p&gt; &lt;input type=&quot;submit&quot; value=&quot;Add&quot; /&gt; &lt;/div&gt; &lt;/form&gt;</pre> <p>And use this new page to display :</p> <pre class="prettyprint">@{ Layout = ""; Page.Title = ""; var pageSize = 10; var totalPages = 0; var count = 0; var page = UrlData[0].IsInt() ? UrlData[0].AsInt() : 1; var offset = (page -1) * pageSize; var db = Database.Open("dbname"); var sql = @"SELECT Count(*) FROM newsarticles "; count = (int)db.QueryValue(sql); totalPages = count/pageSize; if(count % pageSize &gt; 0){ totalPages += 1; } sql = "SELECT Title, Content, Date FROM newsarticles" + "ORDER BY Id DESC OFFSET @0 ROWS FETCH NEXT @1 ROWS ONLY;"; var result = db.Query(sql, offset, pageSize); } &lt;h2&gt;News Articles&lt;/h2&gt; @foreach(var row in result){ &lt;p&gt;@row.Date&lt;br/&gt; &lt;strong&gt;@row.Title&lt;/strong&gt;&lt;br/&gt; @Html.Raw(row.Content.Replace("\n", "&lt;br /&gt;")) &lt;/p&gt; } &lt;p&gt; @{ for (var i = 1; i &lt; totalPages + 1; i++){ &lt;a href="/informations/@i"&gt;@i&lt;/a&gt; } } &lt;span class="alignRight"&gt;&amp;nbsp; Page @page / @totalPages&lt;/span&gt; &lt;/p&gt;</pre> <p><br />You can keep line breaks by using&nbsp;</p> <pre class="prettyprint">@Html.Raw(row.Content.Replace("\n", "&lt;br /&gt;"))</pre> <p><br> <br> </p> 2012-04-13T11:09:22-04:004934579http://forums.asp.net/p/1792462/4934579.aspx/1?Re+paste+news+article+from+word+and+save+in+dbRe: paste news article from word and save in db <p>I assume the reason you are posting from word is to be able to use the formating that you added while in word. &nbsp;There are two ways I can think of to do this.</p> <p>1 make the final document an image and save that to the database. &nbsp;You could also save it as a pdf. &nbsp;An image can easily be saved to a database. These may have scaling issues depending on the screen size and resolution. &nbsp;As an example, online magazines are having to reformat their pages to match the new retena display.</p> <p>2 Include a Rich Text frame in your web site. &nbsp;This also allows some significant security risks and there are some compatability issues that you need to resolve. &nbsp;This frame allows some of the rich text but it is likely moderated and scanned.</p> 2012-04-16T11:34:45-04:004934772http://forums.asp.net/p/1792462/4934772.aspx/1?Re+paste+news+article+from+word+and+save+in+dbRe: paste news article from word and save in db tHanks for that suggestion I think that should do what I need. Not sure if I'll loose formatting in the copy past process but I'll do some testing. 2012-04-16T13:00:39-04:004934777http://forums.asp.net/p/1792462/4934777.aspx/1?Re+paste+news+article+from+word+and+save+in+dbRe: paste news article from word and save in db Thanks Craig, I think I'll check out the rtf frames that you mention. I don't think I want to start storing images of text into the database if I can do it another way. Thanks for the tip 2012-04-16T13:02:13-04:004934866http://forums.asp.net/p/1792462/4934866.aspx/1?Re+paste+news+article+from+word+and+save+in+dbRe: paste news article from word and save in db <p>the one I used was tinymce although there others.&nbsp; Most are javascript plugins that are implimented in a textarea.&nbsp;</p> <p>I'll be happy to answer any questions you have on this.&nbsp; I may save you several hours and probably help me understand it better too.</p> 2012-04-16T13:45:14-04:004935007http://forums.asp.net/p/1792462/4935007.aspx/1?Re+paste+news+article+from+word+and+save+in+dbRe: paste news article from word and save in db Thanks I'll start with checking out tinymce and see how that helps. 2012-04-16T15:10:23-04:004937437http://forums.asp.net/p/1792462/4937437.aspx/1?Re+paste+news+article+from+word+and+save+in+dbRe: paste news article from word and save in db <p>TinyMCE seems really very good although I'm having one problem. When posting back my form data I get the following message:</p> <h2><i>A potentially dangerous Request.Form value was detected from the client (article=&quot;&lt;p&gt;&lt;strong&gt;Rich Text...&quot;).</i></h2> <p>I've tried&nbsp;@Html.Encode on the Request[&quot;&quot;] object but that doesn't seem to help me, have you seen this before?</p> 2012-04-17T21:15:31-04:004937449http://forums.asp.net/p/1792462/4937449.aspx/1?Re+paste+news+article+from+word+and+save+in+dbRe: paste news article from word and save in db <p>Maybe this link could help you: <a href="http://blog.tentaclesoftware.com/archive/2010/07/22/96.aspx" target="_blank"> TinyMCE and A potentially dangerous Request.Form value was detected</a></p> 2012-04-17T21:31:11-04:004941082http://forums.asp.net/p/1792462/4941082.aspx/1?Re+paste+news+article+from+word+and+save+in+dbRe: paste news article from word and save in db <p>Yes, that is one of the problems with merging Javascript and Razor.&nbsp; Any escaping that is done in the Javascript is removed by the request object in the razor section.&nbsp; You will have to use the request.unvalidated().form call to get any of the html that you want to send to razor code.&nbsp; Keep in mind that this data could contain dangerous code such as SQL Injection so you should also escape it immediatly with server.htmlencode if you plan to save it to a database.</p> <p>This is the reason for your getting that warning. The data in Rich Text can contain harmful scripts and you need to keep that in mind when using it.</p> 2012-04-19T12:47:07-04:004941103http://forums.asp.net/p/1792462/4941103.aspx/1?Re+paste+news+article+from+word+and+save+in+dbRe: paste news article from word and save in db <p>Yea not ideal, I've managed to get round it by turning the validation off</p> <p>&nbsp;great editor though so thanks for pointing me towards that</p> 2012-04-19T12:56:21-04:004941238http://forums.asp.net/p/1792462/4941238.aspx/1?Re+paste+news+article+from+word+and+save+in+dbRe: paste news article from word and save in db <p></p> <blockquote><span class="icon-blockquote"></span> <h4>craig_inb</h4> Keep in mind that this data could contain dangerous code such as SQL Injection</blockquote> <p></p> <p>The Request Validation feature in ASP.NET does not protect against SQL Injection. It is there to protect against potential XSS attacks (<a href="http://weblogs.asp.net/jgalloway/archive/2011/04/28/preventing-javascript-encoding-xss-attacks-in-asp-net-mvc.aspx">http://weblogs.asp.net/jgalloway/archive/2011/04/28/preventing-javascript-encoding-xss-attacks-in-asp-net-mvc.aspx</a>). &nbsp;You use input validation and parameters for dynamic values in database commands to protect against SQL injection.</p> 2012-04-19T14:02:12-04:00