Vwa.VwaControl.openDiagram Method

Last modified: June 21, 2012

Applies to: apps for SharePoint | SharePoint Server 2013

Opens a new diagram from a published Visio file (.vsdx, .vsdm) or Visio Web Drawing (.vdw) file located at the specified URL.

var value = VwaControl.openDiagram(string diagramURL, [int pageIndex])

diagramURL A string that specifies the URL of the Web Drawing to open.

pageID An optional integer that specifies the index of the specific Web Drawing page to activate. If you do not specify the index, Visio Services in Microsoft SharePoint Server 2013 opens the first page in the Web Drawing.

Void Returns nothing.

The location specified by diagramURL must be a trusted location.

The openDiagram method is an asynchronous operation that causes an update of the Web Drawing content, and issues a request to the server for the new diagram content if necessary. The method then returns immediately, without waiting for the server to send the new content back to the client. After you call the openDiagram method, you cannot subsequently address the current instance of the VwaControl or of any other object in the Vwa namespace. To correctly follow up on a call to openDiagram, create a handler for the diagramcomplete event and reinstantiate those objects in that event handler.

If you call the openDiagram method while Visio Services is updating the content of the Web Drawing, the method throws an exception.

For more information about how to add a Visio Web Access Web Part to a SharePoint Web Parts page, see Customizing Visio Web Drawings in the Visio Web Access Web Part.

The following example switches the displayed Web Drawing in the Visio Web Access Web Part between two predefined Web Drawings.

<script type="text/javascript">

// Add a button to switch between two predefined URLs.
document.write("<input type='button' id='changeurl' value='Change URL'" +
               "style='width:100px;height:20px' onclick='changeUrl()'>");

// Declare global variables.
var vwaControl;
var diagramUrl1 = "http://[Your SharePoint site]/Shared Documents/[First Web Drawing]";
var diagramUrl2 = " http://[Your SharePoint site]/Shared Documents/[Second Web Drawing]";

// Hook into the AJAX Sys.Application.load event.

// Capture a reference to the current session of the Visio Web Access Web Part.
function onApplicationLoad(){
        vwaControl= new Vwa.VwaControl(getVWAWebPartID());
        currDiagram = diagramUrl1;

// Search the SharePoint page to get the WebPartID# for the Visio Web Access Web Part.
function getVWAWebPartID() {
    // Get a NodesList of all the div tags on the page. 
    var divArray = document.getElementsByTagName("div");
    var webPartElementID;
    // Iterate through the NodesList to get the node with the class attribute "VisioWebAccess."
    for (var i = 0; i < divArray.length; i++) {
        var node = divArray[i];
        // Return the first instance of the Visio Web Access Web Part.
        if (node.className == "VisioWebAccess") {
            webPartElementID = node.parentNode.parentNode.id;
    return webPartElementID;

// Switch the displayed web drawing in the Visio Web Access Web Part.
function changeUrl(){
    // Get the URL of the current file being displayed.
    var currDiagram = vwaControl.getDiagramUrl();
    currDiagram = currDiagram.replace("%20", " ");
    // Replace the currently displayed Web Drawing with the other Web Drawing.
    if (currDiagram == diagramUrl1) {
    else {