September 5, 2008 at 9:22 am
Hi I found one solution for converting RTF to TEXT
Check this out:
http://rinksce15.blogspot.com/2008/09/converting-rtf-to-text-sql-solution.html
Hope you find solution
September 21, 2008 at 5:30 am
How can I convert into plain text the RTF contebts of the text field in my table? Can somebody give help me!
September 21, 2008 at 11:28 am
This is same Dharti check this out:
http://rinksce15.blogspot.com/2008/09/converting-rtf-to-text-sql-solution.html
September 21, 2008 at 1:16 pm
Is there a script that can solve th issue of converting an RTF text field into a plain text output? I don't want to use a converter application and then pass the parameter to a stored procedure its a long process is there any direct solution in SQL server script? Any help will be greatly appreciated...
September 22, 2008 at 8:33 am
Here is the c# code from a .net solution I wrote to solve the problem - the pseudo code is:
Open 2 connections to the server
Fill a datareader with the text data which may be rtf or text
Instantiate a richtextbox control (rtb)
Set the Rtf property to the input text; set string variable txtNoteText to the Text property (stripped of RTF markup)
Use 2nd connection to insert results in new table (NewNote) - you can change this to update a new field in the existing table.
Visual controls include the button to start the process, and textbox to display the record count from time-to-time.
hth,
Eric
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace IntegrityTest3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnGo_Click(object sender, EventArgs e)
{
string txtNoteText = string.Empty;
SqlConnection conn = new SqlConnection( )
SqlConnection conn2 = new SqlConnection( ); //"Driver={SQL Native Client};");
SqlCommand cmd = new SqlCommand("Select NOTEID,NOTETEXT from tbl_NOTE", conn);
SqlCommand cmdInsert=new SqlCommand();
cmdInsert.Connection = conn2;
conn.Open();
conn2.Open();
SqlDataReader rdr = cmd.ExecuteReader();
if(rdr.HasRows)
{
int i=1;
RichTextBox rtb=new RichTextBox();
while (rdr.Read())
{
if (!string.IsNullOrEmpty(rdr["NOTETEXT"].ToString()))
{
try
{ rtb.Rtf = rdr["NOTETEXT"].ToString(); }
catch
{ rtb.Text = rdr["NOTETEXT"].ToString(); }
}
else
{
rtb.Rtf = string.Empty;
}
cmdInsert.CommandText = "INSERT into NewNote VALUES(";
txtNoteText=rtb.Text.Replace("'","_");
string txtNoteID = rdr["NOTEID"].ToString();
cmdInsert.CommandText = string.Format(@"{0}'{1}','{2}')", cmdInsert.CommandText, txtNoteID, txtNoteText);
cmdInsert.ExecuteNonQuery();
i+=1;
if(i % 1000==0)
{
txtCount.Text=i.ToString();
}
}
conn.Close();
}
}
}
}
[font="Tahoma"]Eric Flamm, Flamm Consulting[/font]
September 22, 2008 at 2:22 pm
We have the same problem here - an application that stores RTF data that we want to use in Word mail-merge documents.
We have used two methods to resolve this (both described by Lowell in earlier posts) - firstly, a SQL function that attempts to manually strip out the RTF text. This works Ok, until someone embeds a different bit of formatting that the function doesn't recognise (requiring a change to the function).
Secondly, we have also used the sp_OACreate method, which works really well - EXCEPT, this method has also caused us intermittent locking/blocking problems. I suspect a multi-user conflict of some sort as it works fine for hours/days/etc before failing, but have never been able to pin it down. When it fails, locks are left against all the tables in the mail-merge query and cannot be killed by any method except the sledge-hammer approach of restarting the server - not a nice option.
We are currently on SQL2000 so don't have the luxury of using CLR but, when we upgrade, this would be my next option for providing a final, reliable solution.
Chris
October 26, 2008 at 2:03 pm
following the solution, it's ok for one environment. But if we will have 100 customers then going to 100 customers server and need to install that numbers of VB there, so it's not a costeffective soln. We need to find out way that without having MSWORD, VB, it will work with a SERVER simply with DataBase as SQL Server.
October 26, 2008 at 3:11 pm
i tried going down the CLR route to resolve this in SQL 2005...but guess what... a SQL project is not allowed to have access to an rtf richtextbox control....I guess the idea is a SQL CLR should only fiddle with code, and not with windows forms and their objects...
stupid to limit them in my opinion.
SQL 2005 can consume a web service though; and it's no problem creating a web service that uses CreateObject to use a richtextbox, whether it's vb6 or .NET behind the scenes....
so another option is to create a web service, maybe even on the SQL Server, and have a procedure send the results to a web service.
Lowell
October 27, 2008 at 6:13 am
so before creating web service, I created a small VB application(exe), inside it I tried :
CreateObject("RICHTEXT.RichtextCtrl") [CreateObject("RICHTEXT.RichtextCtrl.1") also tried]
where it's simply unable to create Activex object.
The error msg like "ActiveX component can't create object!"
so again hopeless !!!
October 27, 2008 at 7:06 am
CreataObject assumes there is a dll registered for the object in question....the richtext control is typically registered when vb6 gets installed, and you usually don't install that on a server.
it is MUCH easier in .NET; you simply reference it to it's full path:
Dim rtfObj As New System.Windows.Forms.RichTextBox
i took the very simple example from w3schools from here for a temerature converter, and added an additional rtf conversion as well.
you can download my entire VS2005 solution here:
compile it, add it to IIS and confirm it works, then add a proc that can use the service itself.
this just adds to your arsenal of tools, but I'd expect it to be faster than anything using sp_OaCreate, and even better, it doesn't have that 4000 char handicap for variable values being returned to the calling application.
Lowell
October 27, 2008 at 7:14 am
oh no, at first of all I installed the component 'RICHTX32.OCX'....then only I started...
November 7, 2008 at 8:54 am
Hi Lowell
I have done same, create the function and called it inside the store procedure.
But in SP that column is returning NULL.
If i see the table then there is RTF text in that.
Can you please tell me why this function is returning null while value is there in the table.
November 7, 2008 at 9:32 am
Hi arun;
with 8 pages of RTF examples, using various methods, which function are you using?
if you are using something featuring sp_OaCreate, I'm sure the null gets returned if the richtextbox is not registered correctly; I've tripped over that when i switched laptops.
give me some more information, and especially your function/proc you are using so we can diagnose.
Lowell
November 7, 2008 at 9:54 am
Hi Lowel,
I have used this function
create function dbo.RTF2TXT(@in varchar(8000)) RETURNS varchar(8000) AS
BEGIN
DECLARE @object int
DECLARE @hr int
DECLARE @out varchar(8000)
-- Create an object that points to the SQL Server
EXEC @hr = sp_OACreate 'RICHTEXT.RichtextCtrl', @object OUT
EXEC @hr = sp_OASetProperty @object, 'TextRTF', @in
EXEC @hr = sp_OAGetProperty @object, 'Text', @out OUT
EXEC @hr = sp_OADestroy @object
return @out
END
GO
I have used on a machine which has only SQL2005 and not VB or anything and i can not install VS2005 on this because this is customer machine.
I have also register the dll you have mentioned.
But one think is that when I run this on another machine where i have VS2005 also then it is working fine.
November 7, 2008 at 11:00 am
try this, it is slightly modified; if the dll cannot be created, an error will be raised....that would tell us that you need to register or re-register the RichText and it's dependancies.
create function dbo.RTF2TXT(@in varchar(8000)) RETURNS varchar(8000) AS
BEGIN
DECLARE @object int
DECLARE @hr int
DECLARE @out varchar(8000)
-- Create an object that points to the SQL Server
EXEC @hr = sp_OACreate 'RICHTEXT.RichtextCtrl', @object OUT
if @hr = 0 RAISERROR('Cannot Create RICHTEXT.RichtextCtrl, Not registered correctly, CreateObject Failed.',16,1)
EXEC @hr = sp_OASetProperty @object, 'TextRTF', @in
EXEC @hr = sp_OAGetProperty @object, 'Text', @out OUT
EXEC @hr = sp_OADestroy @object
return @out
END
Lowell
Viewing 15 posts - 61 through 75 (of 105 total)
You must be logged in to reply to this topic. Login to reply