I
IndigoMontoya
Guest
I tried to write this, but I have failed
- I am needing to watch a directory that may or may not exist.
If the directory exists I want to convert any .docx inside to pdf
How shold this code be changed so that it achieves that result?
static FileSystemWatcher fsw = new FileSystemWatcher();
static string[] locations =
{
@"R:\Customer Info\Customer1\Imports\Files\",
@"X:\Info\Imports\Weekly\"
};
static void Main(string[] args)
{
DateTime today = DateTime.Today;
string s_today = today.ToString("MMddyyyy");
foreach (string path in locations)
{
string fullPath = Path.Combine(path + s_today + Path.DirectorySeparatorChar.ToString());
if (Directory.Exists(fullPath))
{
fsw.Path = fullPath;
fsw.Filter = "*.docx";
fsw.Created += OnCreated;
fsw.EnableRaisingEvents = true;
}
}
}
private static void OnCreated(object source, FileSystemEventArgs e)
{
FileInfo file = new FileInfo(e.FullPath);
Convert(file.ToString(), Path.GetDirectoryName(e.FullPath) + Path.DirectorySeparatorChar + "Test.pdf", WdSaveFormat.wdFormatPDF);
Directory.EnumerateFiles(Path.GetDirectoryName(e.FullPath) + Path.DirectorySeparatorChar, "*.docx").ToList().ForEach(x => File.Delete(x));
}
Continue reading...

If the directory exists I want to convert any .docx inside to pdf
How shold this code be changed so that it achieves that result?
static FileSystemWatcher fsw = new FileSystemWatcher();
static string[] locations =
{
@"R:\Customer Info\Customer1\Imports\Files\",
@"X:\Info\Imports\Weekly\"
};
static void Main(string[] args)
{
DateTime today = DateTime.Today;
string s_today = today.ToString("MMddyyyy");
foreach (string path in locations)
{
string fullPath = Path.Combine(path + s_today + Path.DirectorySeparatorChar.ToString());
if (Directory.Exists(fullPath))
{
fsw.Path = fullPath;
fsw.Filter = "*.docx";
fsw.Created += OnCreated;
fsw.EnableRaisingEvents = true;
}
}
}
private static void OnCreated(object source, FileSystemEventArgs e)
{
FileInfo file = new FileInfo(e.FullPath);
Convert(file.ToString(), Path.GetDirectoryName(e.FullPath) + Path.DirectorySeparatorChar + "Test.pdf", WdSaveFormat.wdFormatPDF);
Directory.EnumerateFiles(Path.GetDirectoryName(e.FullPath) + Path.DirectorySeparatorChar, "*.docx").ToList().ForEach(x => File.Delete(x));
}
Continue reading...