How to create a dwg file and save as stream and byte[]

Hello,

I am working on dwg creation using .net Aspose.CAD, version 24.4.
I am facing an issue while saving dwg file as stream and then convert to byte[].
I found the method
public void Save(Stream stream, ImageOptionsBase optionsBase);

Please give me some reference code, thank you!

Here is my current code

            DwgImage dwgImage = new DwgImage();
            //LINE, CIRCLE, ARC, TEXT, POINT, SOLID, 3DFACE and POLYLINE

            //add line
            CadLine line = new CadLine(new Cad3DPoint(0, 0, 0), new Cad3DPoint(100, 100, 100));
            dwgImage.AddEntity(line);
            dwgImage.UpdateSize();

// I want to save to a stream and then convert to byte[]

@msdos41,

Hello,
please, test if this example is useful:

byte[] bytes;

using (var ms = new MemoryStream())
{
	dwgImage.Save(ms);
	bytes = ms.ToArray();
}

@oleksii.gorokhovatskyi

Hello, I tried this method before, and it not worked.
If I use byte[] to convert dwg file, “Drawing file is not valid” error message in AUTOCAD. Also the size of the file is much larger than the file directly saved to local path;

            byte[] bytes;

            using (var ms = new MemoryStream())
            {
                dwgImage.Save(ms);
                bytes = ms.ToArray();
            }
            File.WriteAllBytes(Path.Combine(folderPath, fileName), bytes);

@msdos41,
I can confirm this issue for 24.4 version, but it is not reproducible with the latest Aspose.CAD for .NET 25.5, please consider the update to more recent version.

@oleksii.gorokhovatskyi

My license is only applicable to 24.4, only 1-year. So I cannot use further version.

Any other method to solve this?

And I found this save method the file is actually dxf file, but still cannot open in autocad

@msdos41,
I’m afraid there is no other solution, we apply fixes only to the latest version. You can test if the latest version is more suitable also with free evaluation license and consider update only after this.