ImageGear .NET - Updated
Load a CAD File
User Guide > How to Work with... > CAD > How To ... > Load a CAD File
This section provides information about the following:

Loading a CAD file

The following sample code demonstrates how to load a CAD file using ImageGear.

C#
Copy Code
using System.IO;
using ImageGear.Formats;
using ImageGear.Formats.CAD;

public static void LoadACadFile(string path)
{
    ImGearCADPage page = null;

    // Load the file.
    using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
    {
        page = (ImGearCADPage)ImGearFileFormats.LoadPage(fileStream);
    }
}
VBV.NET
Copy Code
Imports System.IO
Imports ImageGear.Formats
Imports ImageGear.Formats.CAD

Public Sub LoadACadFile(path As String)
    Dim page As ImGearCADPage

    ' Load the file.
    Using fileStream As New FileStream(path, FileMode.Open, FileAccess.Read)
        page = ImGearFileFormats.LoadPage(fileStream)
    End Using
End Sub

Loading a Password Protected DWG File

Loading a password protected DWG file is similar to loading any other CAD file.

C#
Copy Code
using System.IO;
using ImageGear.Formats;
using ImageGear.Formats.CAD;

public static void LoadAPasswordProtectedDwg(string path, string password)
{
    ImGearCADPage page = null;

    // Set the password parameter to the password of the file.
    IImGearFormat format = ImGearFileFormats.Filters.Get(ImGearFormats.DWG);
    format.Parameters.GetByName("Password").Value = password;

    // Load the file.
    using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
    {
        page = (ImGearCADPage)ImGearFileFormats.LoadPage(fileStream);
    }
}
VB.NET
Copy Code
Imports System.IO
Imports ImageGear.Formats
Imports ImageGear.Formats.CAD

Public Sub LoadAPasswordProtectedDwg(path As String, password As String)
    Dim page As ImGearCADPage

    ' Set the password parameter to the password of the file.
    Dim format = ImGearFileFormats.Filters.Get(ImGearFormats.DWG)
    format.Parameters.GetByName("Password").Value = password

    ' Load the file.
    Using fileStream As New FileStream(path, FileMode.Open, FileAccess.Read)
        page = ImGearFileFormats.LoadPage(fileStream)
    End Using
End Sub

Saving a CAD File as Other Supported Formats

See Convert ... for more information.