Thursday, 16 February 2012

Converting RTF to HTML


Posted on September 28, 2009 by Matthew
Have you ever had the desire to convert some RTF text into HTML? Probably not. But if you do, then you are in luck! I recently had the need to do this conversion and after some searching found out a way to do it by enhancing a sample distributed in the MSDN library.  The sample is called:XAML to HTML Conversion Demo


The sample has code which converts HTML to and from a XAML Flow Document.  But this doesn’t make things easier until you realize that there is a way to convert RTF to XAML easily. The key is to use System.Windows.Controls.RichTextBox which can load RTF from a stream and save it as XAML.  This conversion is shown below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
private static string ConvertRtfToXaml(string rtfText)
{
    var richTextBox = new RichTextBox();
    if (string.IsNullOrEmpty(rtfText)) return "";
    var textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
    using (var rtfMemoryStream = new MemoryStream())
    {
        using (var rtfStreamWriter = new StreamWriter(rtfMemoryStream))
        {
            rtfStreamWriter.Write(rtfText);
            rtfStreamWriter.Flush();
            rtfMemoryStream.Seek(0, SeekOrigin.Begin);
            textRange.Load(rtfMemoryStream, DataFormats.Rtf);
        }
    }
    using (var rtfMemoryStream = new MemoryStream())
    {
        textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
        textRange.Save(rtfMemoryStream, DataFormats.Xaml);
        rtfMemoryStream.Seek(0, SeekOrigin.Begin);
        using (var rtfStreamReader = new StreamReader(rtfMemoryStream))
        {
            return rtfStreamReader.ReadToEnd();
        }
    }
}

Interview questions in my interview

->What is Dot Net Architecture?
C# -->CSC(csharp compiler)-->IL Code(Data Type,Source Code)-->\
                                                                                                             \---->CTS(d.t)--->///}MSIL Code->
                                                                                                             /---->CSC(s.c)-->//}     Managed ->                              
VB-->VBC(vb compiler)------>IL Code(Data Type,Source Code)-->/


Code   --->JIT Compiler------>O.S  
   so dot net is Platform Independent because of JIT compiler......  



->What is the Use of Dot Net in Real Time?


->Tell Me about Sql Server?

->What is the Usage and Types of Joins?


->What is Object?


->What is the difference between Abstract and Interface?


->What is Stored Procedure?


 ->What is DDL command?

to display table on DataGrid


private void BtnDisplay_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = "select * from <Table Name>";
            conn.Open();
            SqlDataAdapter da = new SqlDataAdapter(str,conn);
            da.Fill(ds);
            GdvDisplay.DataSource = ds.Tables[0];
            conn.Close();
        }

Using Get Button to get a data from table in C#.net

  private void BtnGet_Click(object sender, EventArgs e)
        {
             string str1 = string.Empty;
            try
            {
            str1 = "select * FROM Registration WHERE SNO='" + TxtSno.Text + "'";

            con.Open();
            da = new SqlDataAdapter(str1, con);
            da.Fill(ds);
           
            TxtName.Text  =ds.Tables[0].Rows[0][1].ToString();
            TxtGender.Text=ds.Tables[0].Rows[0][2].ToString();
            TxtDob.Text   =ds.Tables[0].Rows[0][3].ToString();
            TxtAge.Text   =ds.Tables[0].Rows[0][4].ToString();
       
            }
            catch (Exception ex1)
            {
                MessageBox.Show(ex1.Message);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
           
           
            }


        }

Delete Record on delete button in sql server with C#.net


private void BtnDelete_Click(object sender, EventArgs e)
        {
            string str2 = string.Empty;
         
                try
                {
                    str2 = "delete from Registration where SNO='" + TxtSno.Text + "'";
                    con.Open();
                    SqlCommand cmd = new SqlCommand(str2, con);
                    cmd.ExecuteScalar();
                    TxtAge.Text = TxtDob.Text = TxtGender.Text = TxtName.Text = TxtSno.Text = "";

                }
               
            catch (Exception ex2)
            {
                MessageBox.Show(ex2.Message);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }

            }
        }
       

how to create Save,Delete And Clear Buttons in our appilication usin C#.net With Sql Server back End


Save Button Background Coding in easy way to get It...............

 private void BtnSave_Click(object sender, EventArgs e)
        {
            string str="Insert into Registration(SNO,NAME,GENDER,DOB,AGE) values('"+TxtSno.Text +"','"+TxtName.Text +"','"+TxtGender.Text +"','"+TxtDob.Text +"','"+TxtAge.Text +"')";
            try
            {
                con.Open();
               
                SqlCommand cmd = new SqlCommand(str, con);
                cmd.ExecuteNonQuery();
                TxtAge.Text = TxtDob.Text = TxtGender.Text = TxtName.Text = TxtSno.Text = "";

            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
           
           
            }
        }