///////////////////////////////////////////////TEXT IN DOC : EMBEDD : LOGIC /////////////////////////////////////////////// private void button2_Click(object sender, EventArgs e) { //Checking for validation. if (loadedFilePath == "") { MessageBox.Show("File Path cannot be blank...!"); textBox1.Text = ""; textBox2.Text = ""; } else if (textBox2.Text == "") { MessageBox.Show("Your Msg Should not be blank."); } else if (textBox2.Text.Length > secretmsgsize) { MessageBox.Show("You can Embedd Maximum " + secretmsgsize + " characters."); textBox2.Text = ""; } else { Cursor.Current = Cursors.WaitCursor; SimpleObjectFactory sof = new SimpleObjectFactory(); ITextFile textFile = sof.getTextFile(); string text = textFile.getTextFromFile(loadedFilePath); string msg = textBox2.Text; ITextInDoc textInDoc = sof.getTextInDoc(); text = textInDoc.Embedd(text, msg); string path = loadedFilePath.Remove(loadedFilePath.Length - fileNameSize) + justFName(loadedFilePath).Remove(fileNameSize - 4) + "1.txt"; if (!File.Exists(path)) { File.Create(path).Dispose(); using (TextWriter tw = new StreamWriter(path)) { tw.Write("" + text + ""); tw.Close(); } label33.Text = "Output File : " + path; } else if (File.Exists(path)) { using (TextWriter tw = new StreamWriter(path)) { MessageBox.Show(justFName(loadedFilePath).Remove(fileNameSize - 4) + "1.txt File already exist...!"); label33.Text = ""; } } Cursor.Current = Cursors.Arrow; textBox1.Text = ""; textBox2.Text = ""; msg = ""; loadedFilePath = ""; } }
////////////////////////////////////////////TEXT IN DOC : EXTRACT : LOGIC /////////////////////////////////////////////// private void button4_Click(object sender, EventArgs e) { if (loadedFilePath == "") { MessageBox.Show("File Path cannot be blank...!"); } else { Cursor.Current = Cursors.WaitCursor; SimpleObjectFactory sof = new SimpleObjectFactory(); ITextFile textFile = sof.getTextFile(); string text = textFile.getTextFromFile(loadedFilePath); ITextInDoc textInDoc = sof.getTextInDoc(); text = textInDoc.Extract(text); textBox11.Text = text; loadedFilePath = ""; Cursor.Current = Cursors.Arrow; } }