
How to Open and View DWG Files in .NET Apps – Answering plik dwg and que es dwg
What is a DWG file?
DWG is the native binary format used by AutoCAD to store 2‑D and 3‑D design data. It contains vector geometry, layers, text, and metadata that describe engineering drawings, floor plans, mechanical parts, and similar technical schematics. Because the format is proprietary, most generic image viewers cannot interpret the geometry; a dedicated CAD parser is required.
Why a .NET developer needs to render DWG in a web portal
If your solution is a document‑centric portal—whether a DMS, a CRM, an engineering portal, or a legal‑tech case viewer—you will inevitably receive DWG files from architects, mechanical engineers, or contractors. Users expect to preview those files instantly, without downloading a heavy desktop CAD program. Providing an in‑browser preview eliminates friction, reduces support tickets, and keeps the workflow inside your secure application boundary.
Converting DWG to PDF for fallback scenarios
Not every client can render vector CAD directly (e.g., older browsers or screen‑readers). Converting DWG to PDF gives you a universally viewable representation while preserving line work and layer visibility.
Doconut’s Converter Plugin can perform this conversion server‑side:
- No Microsoft Office or AutoCAD installation is required.
- The conversion runs inside your .NET process or Docker container, keeping the data under your control.
- The output PDF can be cached and reused for subsequent views, reducing CPU load.
Typical flow:
- Invoke the converter with the path (or stream) of the DWG file.
- Receive a PDF file (as a path or stream).
- Store the PDF alongside the original DWG for quick lookup.
Displaying DWG directly in a .NET front‑end
When you want the full CAD experience—zoom, pan, layer toggling—use Doconut’s Universal Document Viewer. The viewer accepts DWG files natively, parses the vector data on the server, and streams image tiles to the browser. The client receives HTML/JavaScript that renders the tiles in a canvas, providing a smooth, Office‑free experience.
Key points for integration:
- Register the viewer middleware in your ASP.NET Core pipeline (e.g.,
app.UseDoconut(...)). - The middleware handles tile requests automatically, so no extra routing code is needed.
- Because the viewer works with streams, you can feed it directly from the temporary storage you created earlier.
The result is an embeddable <iframe> or a ready‑made React/Angular/Vue component that displays the DWG with interactive zoom, pan, and layer controls, all inside your web page.
Putting it together: an end‑to‑end DWG preview workflow
- Upload – User drags a DWG file onto your portal.
- Validate & store – Server checks the file and saves it.
- Optional conversion – If you need a PDF fallback, invoke the Converter Plugin and cache the PDF.
- Render – Use the Doconut SDK to open the DWG document and obtain a viewer token. The viewer middleware then serves the required tiles to the front‑end.
- Interact – Users can zoom, pan, and toggle layers. If they click “Download PDF”, you serve the cached PDF from step 3.
All of these steps happen inside your .NET 6/8 application, without requiring any external CAD binaries, Office installations, or third‑party services.
Add the Doconut NuGet package to your solution, configure the viewer middleware, and try uploading a sample DWG exported from AutoCAD. You’ll see the file render instantly in the browser, and with a single line of code you can also generate a PDF for users who prefer a static view. This integration satisfies the requirement and lets you show DWG content directly to your stakeholders.