How can I save my documents to database sql server and open it.

2 posts, 0 answers
  1. Jornesio
    Jornesio avatar
    1 posts
    Member since:
    Aug 2013

    Posted 04 Feb 2015 Link to this post

    How can I save my documents to database sql server and open it.

    I am using the control RichTextEditorRibbonBar

    I want armagenar all information in the database and access starting from the database as well.

    I want save all information (Doc,Richt,PDF) in the database and access starting from the database as well.

    and export to my computer when necessary

    I can not edit the elements "RibbonBar" to Portuguese
    I can not also see the code to change to my taste


    automatically configures  and not the possibility of choice

     Try--------------------------------------------SAVE-------------------------------------------------
                rtbDoc.SaveFile("temp.rtf")
                stream = New FileStream("temp.rtf", FileMode.Open, FileAccess.Read)
                Dim size As Integer = Convert.ToInt32(stream.Length)
                Dim rtf As [Byte]() = New [Byte](size - 1) {}
                stream.Read(rtf, 0, size)

                Dim paramRTF As New SqlParameter("@Documento", SqlDbType.VarBinary, rtf.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, rtf)
                '    cmd.Parameters.Add(paramRTF)
                Using connection As New SqlClient.SqlConnection(Ligarservidor)
                    connection.Close()
                    Dim SQL As String = "INSERT INTO doc (ID,Processo,data,tipo,Documento) VALUES (@ID,@Processo,@data,@Tipo,@Documento);"
                    Dim command As New SqlCommand(SQL, connection)
                    command.Parameters.AddWithValue("@ID", SqlDbType.NVarChar).Value = "1"
                    command.Parameters.AddWithValue("@Processo", SqlDbType.NVarChar).Value = "W"
                    command.Parameters.AddWithValue("@Data", SqlDbType.NVarChar).Value = "W"
                    command.Parameters.AddWithValue("@Tipo", SqlDbType.NVarChar).Value = "W"
                    command.Parameters.Add(paramRTF)
                    connection.Open()
                    command.ExecuteNonQuery()
                    MessageBox.Show("Informação registada!...", "Info")
                End Using
            Catch ex As Exception
            Finally
                If stream IsNot Nothing Then
                    stream.Close()
                End If

            End Try




    -------------------------------------------------------------READ------------------------------------------------------------------
      Dim cn As SqlConnection = Nothing
            Dim cmd As SqlCommand = Nothing
            Dim reader As SqlDataReader = Nothing
            Try
                cn = New SqlConnection(Ligarservidor)
                cn.Open()
                cmd = New SqlCommand("SELECT documento FROM doc WHERE ID=1", cn)
                reader = cmd.ExecuteReader()
                reader.Read()
                If reader.HasRows Then
                    If Not reader.IsDBNull(0) Then
                        Dim rtf As [Byte]() = New [Byte](Convert.ToInt32((reader.GetBytes(0, 0, Nothing, 0, Int32.MaxValue))) - 1) {}
                        Dim bytesReceived As Long = reader.GetBytes(0, 0, rtf, 0, rtf.Length)

                        Dim encoding As New ASCIIEncoding()
                        rtbDoc.Rtf = encoding.GetString(rtf, 0, Convert.ToInt32(bytesReceived))
                    End If
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            Finally
                If reader IsNot Nothing Then
                    reader.Close()
                End If
                If cn IsNot Nothing Then
                    cn.Close()
                End If
            End Try


  2. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 05 Feb 2015 Link to this post

    Hello Jornesio,

    Thank you for writing.

    Your question has already been answered in the support thread that you have opened on the same topic. However, I am posting the answer here as well in order the community to benefit from it.

    RadRichTextEditor allows you to export its content to the following formats: XAML, DOCX, HTML, RTF, Plain text, PDF. Afterwards, you can store the exported file in a datatable in your SQL server. You can find useful information about storing files in SQL server on the following links:

    Currently, RadRichTextEditor does not support localization provider for its RibbonUI. However, we already have a similar request logged in our feedback portal. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - feedback item.

    As to the question related to changing the performed action for some buttons, you are not allowed to do that. However, you can add new items to the RichTextEditorRibbonBar.BackstageControl, e.g. a BackstageButtonItem and replace an existing item with your custom one:

    Public Sub New()
        InitializeComponent()
     
        'hide the default "Save as" button
        Me.RichTextEditorRibbonBar1.BackstageControl.Items.Last().Visibility = ElementVisibility.Collapsed
     
        'create your own button
        Dim backstageButtonSaveAs As New BackstageButtonItem()
        AddHandler backstageButtonSaveAs.Click, AddressOf backstageButtonSaveAs_Click
        backstageButtonSaveAs.Text = "My save as button"
        Me.RichTextEditorRibbonBar1.BackstageControl.Items.Add(backstageButtonSaveAs)
    End Sub
     
    Private Sub backstageButtonSaveAs_Click(sender As Object, e As EventArgs)
        RadMessageBox.Show("Save")
    End Sub

     

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Dess
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top