How to get VDX format from VSDX using Visio 2013 or higher? - visio

Starting from Microsoft Visio 2013 support for VSD documents has been ended. Our App has a requirement to convert VSDX to VDX using Visio 2013 but I couldn’t find a way to do.
I tried to use Visio interop DLL to open invisible Visio App and tried to use SaveAs to save my VSDX as VDX. Code compiles and runs without any error and I get a .VDX file as output. When I try to view that generated VDX file using Visio viewer it fails. It says
Microsoft viewer cannot complete this operation
Wasn’t it generated as a healthy file?
We need to move away from Visio 2010 to Visio 2019. We would need to find a way to support both VSDX and VDX formats until all our apps are migrated. I have used below POC to convert .vsdx to .vdx or to convert .vsd to .vdx both of which dint work when i tried to view using Visio viewer . -
There were few articles where suggested me to use below POC to convert .VSDX to .VDX or to convert a .VSD to .VDX , both of which dint work. So .VSD to .VDX is not possible at all unless i use a Visio 2010 editor ?
// Create Visio Application Object
Visio.Application vsdApp = new Visio.Application();
// Make Visio Application Invisible
vsdApp.Visible = false;
// Create a document object and load a diagram
Visio.Document vsdDoc = vsdApp.Documents.Open(dataDir + "Drawing1.vsd");
// Save the VDX diagram
vsdDoc.SaveAs(dataDir + "SaveDiagramToVDXwithVSTO_out.vdx");
Link referred - https://csharp.hotexamples.com/examples/Microsoft.Office.Interop.Visio/Application/-/php-application-class-examples.html

The "Save-As VDX" feature was really-really removed in Visio 2013. Even from the API. If you call .SaveAs passing name with .vdx extension what you actually get is .vsd binary file, just with extension .vdx. You can make sure of that by simply viewing the produced file in notepad - it's not xml.
When you try to load that file in the viewer, it tries to parse it as xml, but fails, because file is actually a binary file, thus you get this error.
If you need to support .vdx, stick to Visio 2010.

Related

Can OpenXML be used to launch a new Word instance?

I'm able to generate Word documents without issue. I save the resulting *.docx file to a temporary location and then need to launch the file in Word.
The requirement is to not "open" the file in Word (easily done with a Process.Start) but to have load into Word as a new unsaved file. This is because certain propriety integrations for Word need to take over when a user saves the file and don't kick in if the file is ready saved but to a location on disk.
I've achieved this by using Interop calls to the Word application, adding the new document to Word's workspace. My problem is with Interop which tends to break on various client machines, particularly when Office upgrades take place (say a client had 32-bit office but upgraded with a 64-bit version).
I'm somewhat new to OpenXML, but can it be used to automate Word or is Interop my only real option?
object oFilename = tmpFileName;
object oNewTemplate = false;
object oDocumentType = 0;
object oVisible = true;
Document document = _application.Documents.Add(ref oFilename, ref oNewTemplate, ref oDocumentType, ref oVisible);
No, the Open XML technology has no way of interacting with the Office (Word) application - it's for file creation/manipulation, only. The interop is required in order to do anything with the Word application.
There is sort of a way around this - and it's only possible with Word, no other Office application has this - is to convert the Open XML content to the OPC flat-file format. This "concatenates" the various packages that make up the zip file to a pure text string, essetially a single XML file.
XML content in the OPC flat-file format can then be written to an already opened (even newly created) Word document using the Range.InsertXML method via "the interop". In a way, this "streams" the Open XML content into the opened Word document.
The problem with this approach is that certain document-level properties are not written to the target document, so not all aspects of the opened document can be changed. For example: page size, orientation, headers, footers... So if this kind of thing also needs to be affected the interop is required for such settings.

Open a file from crystal report export to stream function

How can i open a file directly from stream which is exported through crystal report export to stream function? I am using vs2010 and sap crystal report.
MemoryStream m = (MemoryStream)(PReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat));
FileStream f = new FileStream(purchaseCombo.SelectedItem.ToString(),FileMode.Create,System.IO.FileAccess.Write);
byte[] bytes = new byte[m.Length];
m.Read(bytes, 0, (int)m.Length);
f.Write(bytes, 0, bytes.Length);
f.Close();
m.Close();
It depends on the file that you are exporting. Since Crystal Reports can export a number of different file types and each of them has a specific program that can handle it, you will need to search for the exact file type that you're interested. For example with a quick search on the internet, I found that a stream of an html file can be directly previewed inside a WebBrowser component (in a WPF app) by using the NavigateToStream method. Maybe there are some 3rd party components that expose methods for directly opening files from memory.
Though, the easiest way would be to export a temporary file to disk instead of memory by using the ExportToDisk method and delete it after its usage, since many components read from paths rather than memory. Before exporting the file, you can use the GetTempFileName method which creates and names a temporary file.

Replacing aspose JRPptExporterParameter.PPT_TEMPLATE_PRESENTATION in jasperreports 5.0

I am generating a ppt report using jasperreports and aspose library (ppt exporter from aspose). I'm trying to eliminate aspose from the project and use the ppt exporter from jasperreports 5.0. The problem is that at the moment the generated report needs an external .pot file which is added using aspose:
com.aspose.slides.jasperreports.JRPptExporter exporter = new com.aspose.slides.jasperreports.JRPptExporter();
......
exporter.setParameter(com.aspose.slides.jasperreports.JRPptExporterParameter.PPT_TEMPLATE_PRESENTATION, pptTemplate);
exporter.exportReport();
I didn't find any similar parameter in JRExporterParameter from jasperreports and I couldn't find any efficient solution yet. Is there any method of using an external .pot file? I was thinking about creating a second JasperPrint object from the .pot file and then exporting both JasperPrint objects setting JRExporterParameter.JASPER_PRINT_LIST
Not sure if that fits for you, but I've written a custom PPTX Exporter (only pptx, not binary ppt), which is based on Apache POI. The POI element can be initalized by your own template pptx (not yet implemented in my version).
https://code.google.com/p/pptx-shape-exporter/
Drop me a line, if this sounds interesting to you.

can open xml sdk be used in creating xml files?

is it possible to use the OPEN XML SDK and generate an xml file that contains some metadata of a particular docx file?
details: i have a docx file, from which i want to extract some metadata(using open xml) and display them as xml file and later use Jquery to present them in a more readable form.
You can use the SDK to extract info from the various properties parts which may be present in the docx (for example, the core properties part, which included dublin core type info).
You can extract it in its native XML form:
<cp:coreProperties
xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core- properties"
xmlns:dc="http://purl.org/dc/elements/1.1/" .. >
<dc:creator>Joe</dc:creator>
<cp:lastModifiedBy>Joe</cp:lastModifiedBy>
<cp:revision>1</cp:revision>
<dcterms:created xsi:type="dcterms:W3CDTF">2010-11-10T00:32:00Z</dcterms:created>
<dcterms:modified xsi:type="dcterms:W3CDTF">2010-11-10T00:33:00Z</dcterms:modified>
</cp:coreProperties>
or, in some other XML dialect of your own choosing.
I know question was posted a long time ago, but first result of google search sent me here. So if there are others looking for a solution to this, there is a snippet on MSDN website https://msdn.microsoft.com/en-us/library/office/cc489219.aspx
short answer is... using XmlTextWritter, and it applies to Office 2013 afaik:
// Add the CoreFilePropertiesPart part in the new word processing document.
var coreFilePropPart = wordDoc.AddCoreFilePropertiesPart();
using (XmlTextWriter writer = new XmlTextWriter(coreFilePropPart.GetStream(FileMode.Create), System.Text.Encoding.UTF8))
{
writer.WriteRaw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<cp:coreProperties xmlns:cp=\"http://schemas.openxmlformats.org/package/2006/metadata/core-properties\"></cp:coreProperties>");
writer.Flush();
}

Do we have any Equivalent of Response.AppendHeader in windows application

I came around this technique of converting datatable to excel
http://www26.brinkster.com/mvark/dyna/downloadasexcel.html
Do we have any Equivalent of Response.AppendHeader in windows application in C#.
Regards
Hema
The trick in the code sample that you have mentioned to dynamically generate an Excel file is based on the fact that documents can be converted from Word/Excel to HTML (File->Save As) and vice versa. Essentially a HTML page containing Office XML is created & in a web application a file download is triggered with the help of the following Response.AppendHeader statements -
Response.AppendHeader("Content-Type", "application/vnd.ms-excel");
Response.AppendHeader("Content-disposition", "attachment; filename=my.xls");
If you want to use this technique in a Winforms application, just save the string content as a text file and give the file an extension of ".xls". Instead of the last 3 lines in the sample's Page_Load method, replace it with this line -
System.IO.File.WriteAllText(#"C:\Report.xls", strBody);
HTH