NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using Spire.Doc;

namespace MertTestUygulama
{
public partial class Form4 : Form
{
private FileInfo[] Files;
List<TextBox> textboxs = new List<TextBox>();
Document document = new Document();
Dictionary<string, string> dictionary = new Dictionary<string, string>();
Dictionary<string, string> filesDictionary = new Dictionary<string, string>();
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application { Visible = false };
private static Microsoft.Office.Interop.Word.Document aDoc;
private string selectedFilePath = "";
private string selectedSavePath = "";
public Form4()
{
InitializeComponent();
}

private void Form4_Load(object sender, EventArgs e)
{
getDocxDocuments();
textBox1.Text = selectedSavePath;
}



private void listBox1_DoubleClick(object sender, EventArgs e)
{
MessageBox.Show(listBox1.SelectedItem.ToString());
selectedFilePath = filesDictionary[listBox1.SelectedItem.ToString()];
createDirectory();
}
private void getDocxDocuments()
{
/*Set default save folder*/
selectedSavePath = Directory.GetCurrentDirectory();

DirectoryInfo directoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory());
try
{
Files = directoryInfo.GetFiles("*.docx");
if (Files.Length >= 1)
{
foreach (FileInfo file in Files)
{
listBox1.Items.Add(file.Name);
filesDictionary.Add(file.Name,file.FullName);
}
}
else
{
listBox1.Items.Add("Bulunamadı.");
}

}
catch (Exception exception)
{
MessageBox.Show("Dosyaları alırken bir sorun oluştu: " + exception);
}
}
private void createDirectory()
{

Regex regex = new Regex("<[^>]*>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
document.LoadFromFile(selectedFilePath);
MatchCollection matches = regex.Matches(document.GetText());
foreach (var match in matches)
{
if (!dictionary.ContainsKey(match.ToString()))
dictionary.Add(match.ToString(), "Karşılığını ayarlayınız.");
}
int xindextext = 280;
int xindexlabel = 185;
int y = 0;
for (int i = 0; i < dictionary.Count; i++)
{
if (i%10 == 0)
{
xindexlabel += 97;
xindextext += 97;
y = 0;
}

TextBox newTextBox = new TextBox();
newTextBox.Location = new Point(xindextext, 22 + (25 * y));
newTextBox.Size = new Size(240, 30);
newTextBox.Text = dictionary.ElementAt(i).Value;
this.Controls.Add(newTextBox);
textboxs.Add(newTextBox);

List<Label> labels = new List<Label>();
Label newLabel = new Label();
newLabel.Location = new Point(xindexlabel, 22 + (25 * y));
newLabel.Text = dictionary.ElementAt(i).Key;
this.Controls.Add(newLabel);
labels.Add(newLabel);
y++;
}
}

private void replaceandSave()
{
string filePath = selectedFilePath;
string fileName = filesDictionary.FirstOrDefault(x => x.Value == selectedFilePath).Key;
aDoc = wordApp.Documents.OpenNoRepairDialog(filePath);

foreach (var theVariable in dictionary)
{
FindAndReplace(wordApp, theVariable.Key, theVariable.Value);
}
aDoc.SaveAs(selectedSavePath+"\"+"new_"+fileName);
aDoc.Close(true);
}
private void FindAndReplace(Microsoft.Office.Interop.Word.Application doc, object findText, object replaceWithText)
{
//options
object matchCase = false;
object matchWholeWord = true;
object matchWildCards = false;
object matchSoundsLike = false;
object matchAllWordForms = false;
object forward = true;
object format = false;
object matchKashida = false;
object matchDiacritics = false;
object matchAlefHamza = false;
object matchControl = false;
object read_only = false;
object visible = true;
object replace = 2;
object wrap = 1;
//execute find and replace
doc.Selection.Find.Execute(ref findText, ref matchCase, ref matchWholeWord,
ref matchWildCards, ref matchSoundsLike, ref matchAllWordForms, ref forward, ref wrap, ref format, ref replaceWithText, ref replace,
ref matchKashida, ref matchDiacritics, ref matchAlefHamza, ref matchControl);
}

private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.ShowDialog();
selectedSavePath = folderBrowserDialog.SelectedPath;
textBox1.Text = selectedSavePath;
}

private void button2_Click(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
for (int i = 0; i < textboxs.Count; i++)
{
TextBox text = textboxs[i];
dictionary[dictionary.ElementAt(i).Key] = text.Text;
}

replaceandSave();
}
}

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
button2.Enabled = true;
else
button2.Enabled = false;
}

private void Form4_FormClosed(object sender, FormClosedEventArgs e)
{

}
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.