←Select platform

RejectInvalidFileId Property

Summary
Gets or sets a value indicating whether the methods of the DicomDir class that take a filename as a parameter should fail if the number of components in the File ID exceeds 8 or if the number of characters in any component of the File ID exceeds 8.
Syntax
C#
Objective-C
C++/CLI
public bool RejectInvalidFileId { get; set; } 
@property (nonatomic, assign) BOOL rejectInvalidFileId; 
public: 
property bool RejectInvalidFileId { 
   bool get(); 
   void set (    bool value); 
} 

Property Value

true if the methods of the DicomDir class that take a filename as a parameter should fail if: - the number of components in the File ID exceeds 8 - the number of characters in any component of the File ID exceeds 8 (possible only for the last component, since the short format of filenames is used for File IDs); - any character other than those allowed by DICOM specification is used (valid characters include capitals A-Z, 0-9, and underscores). otherwise, false.

Remarks

As an example, if the destination folder is specified as "C:\DICOM Images\", then the following filenames will be rejected if RejectInvalidFileId is set to true: "C:\DICOM Images\Sub1\Sub2\Sub3\Sub4\Sub5\Sub6\Sub7\Sub8\Brain"

"C:\DICOM Images\Patient 1\CT-10-Knee.dic"

The first filename is rejected because the number of components in the File ID exceeds 8 (there are 9 components, starting from "Sub1") and because lower case letters and spaces are used. The second filename is rejected because the number of characters in the last component, which is the short format of "CT-10-Knee.dic" (e.g., "CT-10-~1.dic") exceeds 8 and because lower case letters and spaces are used. On the other hand, the following filenames will not be rejected:

"C:\DICOM Images\SUB1\SUB2\SUB3\SUB4\SUB5\SUB6\SUB7\BRAIN"

"C:\DICOM Images\PATIENT1\KNEE"

Example
C#
using Leadtools; 
using Leadtools.Dicom; 
 
 
public class MyDicomDir : DicomDir 
{ 
   public MyDicomDir(string destinationFolder, string path) : base(destinationFolder, path) { } 
   public override DicomDirInsertFileCommand OnInsertFile(string fileName, DicomDataSet ds, DicomDirInsertFileStatus status, DicomExceptionCode code) 
   { 
      if (status == DicomDirInsertFileStatus.PreAdd) 
      { 
         string msg = string.Format("About to add the file '{0}'{1}{1}Proceed?", fileName, Environment.NewLine); 
         Console.WriteLine($"{msg}"); 
         return DicomDirInsertFileCommand.Continue; 
 
      } 
      else if (status == DicomDirInsertFileStatus.Success) 
      { 
         string msg = string.Format("The file '{0}' has been added successfully.", fileName); 
         Console.WriteLine(msg); 
      } 
      return DicomDirInsertFileCommand.Continue; 
   } 
}; 
 
public void CreateDicomDirectory() 
{ 
   //Make sure to initialize the DICOM engine, this needs to be done only once  
   //In the whole application 
   DicomEngine.Startup(); 
   using (MyDicomDir dicomDir = new MyDicomDir(null, null)) 
   { 
      bool autoSearch = true; 
      // Set the destination folder 
      dicomDir.Reset(Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "HeadCBCT")); 
      // Set the File-set Identifier 
      dicomDir.SetFileSetId("SOME_ID"); 
      // Set some options 
      DicomDirOptions options = dicomDir.Options; 
      dicomDir.ResetOptions(); 
      options.IncludeSubfolders = true; 
      options.InsertIconImageSequence = false; 
      options.RejectInvalidFileId = true; 
      dicomDir.Options = options; 
 
      // Set the File-set descriptor file 
      string path = Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "HeadCBCT", "README"); 
      dicomDir.SetDescriptorFile(path, null); 
 
      if (autoSearch) 
      { 
         try 
         { 
            dicomDir.InsertFile(null); 
         } 
         catch (Exception ex) 
         { 
            Console.WriteLine($"{ex.GetType().ToString()} {ex.Message}"); 
         } 
      } 
      else 
      { 
         // Load a Data Set and add it to the Directory 
         using (DicomDataSet ds = new DicomDataSet()) 
         { 
            ds.Load(Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "HeadCBCT", "CT", "CT_001"), DicomDataSetLoadFlags.None); 
            dicomDir.InsertDataSet(ds, Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "HeadCBCT", "CT", "CT_001")); 
         } 
 
         // Add some DICOM files to the Directory 
         dicomDir.InsertFile(Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "HeadCBCT", "CT", "CT_002")); 
         dicomDir.InsertFile(Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "HeadCBCT", "CT", "CT_003")); 
      } 
 
      // Test the DataSet 
      DicomElement first = dicomDir.DataSet.FindFirstElement(null, DicomTag.PatientID, false); 
      Console.WriteLine(first.Length.ToString()); 
 
      // Save the DICOMDIR File 
      dicomDir.Save(); 
      //We can now call something like this to call the DICOMDIR back 
      //dicomDir.Load(LeadtoolsExamples.Common.ImagesPath.Path + @"TEMP\DCMTEST\PATIENT1\DICOMDIR",DicomDataSetLoadFlags.LoadAndClose); 
   } 
   DicomEngine.Shutdown(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.8.20
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Dicom Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.