Word Decrypt in C#, VB.NET

  • Demo
  • C# source
  • VB.Net source

The sample demonstrates how to decrypt a document.

private void button1_Click(object sender, EventArgs e)
{
    string fileName = OpenFile();
    if (!string.IsNullOrEmpty(fileName))
    {
        //Create word document
        Document document = new Document();
        document.LoadFromFile(fileName,FileFormat.Doc,this.textBox1.Text);

        //Save doc file.
        document.SaveToFile("Sample.doc", FileFormat.Doc);

        //Launching the MS Word file.
        WordDocViewer("Sample.doc");
    }


}

private string OpenFile()
{
    openFileDialog1.Filter = "Word Document (*.doc)|*.doc";
    openFileDialog1.Title = "Choose a document to Decrypt";

    openFileDialog1.RestoreDirectory = true;
    if (openFileDialog1.ShowDialog() == DialogResult.OK)
    {
        return openFileDialog1.FileName;
    }

    return string.Empty;
}

private void WordDocViewer(string fileName)
{
    try
    {
        System.Diagnostics.Process.Start(fileName);
    }
    catch { }
}

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
	Dim fileName As String = OpenFile()
	If Not String.IsNullOrEmpty(fileName) Then
		'Create word document
		Dim document_Renamed As New Document()
		document_Renamed.LoadFromFile(fileName,FileFormat.Doc,Me.textBox1.Text)

		'Save doc file.
		document_Renamed.SaveToFile("Sample.doc", FileFormat.Doc)

		'Launching the MS Word file.
		WordDocViewer("Sample.doc")
	End If


End Sub

Private Function OpenFile() As String
	openFileDialog1.Filter = "Word Document (*.doc)|*.doc"
	openFileDialog1.Title = "Choose a document to Decrypt"

	openFileDialog1.RestoreDirectory = True
	If openFileDialog1.ShowDialog() = DialogResult.OK Then
		Return openFileDialog1.FileName
	End If

	Return String.Empty
End Function

Private Sub WordDocViewer(ByVal fileName As String)
	Try
		Process.Start(fileName)
	Catch
	End Try
End Sub

Coupon Code Copied!

Christmas Sale

Celebrate the season with exclusive savings

Save 10% Sitewide

Use Code:

View Campaign Details