Hello,
I have the problem that my code (using PdfSharp) is thworing an "NullReferenceException" at the point
Thanks in advance!
I have the problem that my code (using PdfSharp) is thworing an "NullReferenceException" at the point
outputDocument.AddPage(page);
and I dont know why. You can find a snippet of my code with the important things below:
C#:
public static void CreatePDFx(string path)
{
// Files beinhaltet alle Dateien pro Patientenordner (Bezeichnungen)
string[] files = GetFiles(path);
// Open the output document
PdfDocument outputDocument = new PdfDocument();
int numberOfDocs = 0;
// Iterate files
foreach (string file in files)
{
// Open the document to import pages from it.
PdfDocument inputDocument = PdfReader.Open(file, PdfDocumentOpenMode.Import);
// Iterate pages
int count = inputDocument.PageCount;
for (int idx = 0; idx < count; idx++)
{
// Get the page from the external document...
PdfPage page = inputDocument.Pages[idx];
// ...and add it to the output document.
outputDocument.AddPage(page);
}
}
}
public static void StartWatchers()
{
List<FileSystemWatcher> watchers = new List<FileSystemWatcher>();
string[] ward_folders = Directory.GetDirectories(@"C:\OfflineDocuments\");
watchers.Add(MyWatcherFatory(@"C:\OfflineDocuments\"));
//Fehlerhaft
int j = 0;
foreach (string ward_folder in ward_folders)
{
j++;
string[] pat_folders = Directory.GetDirectories(ward_folder);
int i = 0;
foreach (string pat_folder in pat_folders)
{
CreatePDFx(pat_folder);
i++;
}
foreach (FileSystemWatcher watcher in watchers)
{
watcher.EnableRaisingEvents = true; ;
i++;
}
}
}
Thanks in advance!
Last edited: