在SharePoint 2010中动态加载Visio Web Part

今天跟同事讨论一个关于Visio Web Part的问题。需求大抵是这样的:在SharePoint文档库中有一系列已经发布的Visio图形,我想在页面中动态的根据一些逻辑来显示出来。我希望是通过JavaScript的代码实现。

首先第一个问题,在页面中显示Visio图形。这个比较简单,SharePoint 2010中提供了Visio Web Access这个web Part控件。你可以通过指定Web Part的属性,来轻松显示Visio图形。

第二个问题,动态显示,这个问题稍微有些难度。因为Visio Web Access中的Visio图形的地址已经提前指定好了。怎么办呢?幸运的是,在SharePoint 2010中,增加了Visio Services Class Library,这是一些列封装好了的JavaScipt。其中提供了针对Visio的类,如下图:(具体参考:http://msdn.microsoft.com/en-us/library/ee557781.aspx)

Name

Description

Vwa.VwaControl Class

Represents an instance of the Visio Web Access Web Part.

Vwa.Page Class

Represents the page that is currently displayed in the rendering area of the Visio Web Access Web Part.

Vwa.ShapeCollection Class

Represents the collection of Shape objects on the active page displayed in the rendering area of the Visio Web Access Web Part.

Vwa.Shape Class

Represents a single Shape object on the active page displayed in the rendering area of the Visio Web Access Web Part.

我们这里使用的是Vwa.VwaControl.openDiagram() 方法来实现动态加载Visio图形的需求。

逻辑:逻辑并不复杂。就是在visio 图形加载完毕之后重新制定一个新的Visio图形的URL;

技术实现:使用Visio Web Access + 内容编辑web部件。

具体操作:

1. 通过IE Developer来检查一下当前页面的Visio图形所在的Web Part的ID。

image

2.在本地的文本文件中写处理逻辑的代码,然后上传到文档库。代码如下:

<script type="text/javascript">
Sys.Application.add_load(onApplicationLoad);

var webPartElementID = "WebPartWPQ2";
var vwaControl;
function onApplicationLoad() {
        try{            
                vwaControl= new Vwa.VwaControl(webPartElementID)                    
                vwaControl.addHandler("diagramcomplete", onDiagramComplete);                  
        }
        catch(err){
        }
}

function onDiagramComplete() {
        try{            
                vwaControl.openDiagram("http://servername:port/DocLibA/Drawing2.vdw");
                vwaControl.removeHandler("diagramcomplete",onDiagramComplete);    
        }
        catch(err){
        }
}

</script>

3.页面中添加内容编辑Web部件,并且指定“内容链接(Content Link)”属性到刚刚上传到文档库的js文件。

保存测试效果。

当然我这里仅仅完成需求的一部分。剩余的部分,就是如何去处理并且形成“vwaControl.openDiagram()”的参数。

posted @ 2011-06-23 11:19  范文轩  阅读(1182)  评论(0编辑  收藏  举报