Use the Visio Viewer to load the Visio diagram in the database

Source: Internet
Author: User
Tags file url visio viewer

The requirement is very simple. In the SQL Server database, store the user-uploaded Visio file, and then use the Visio Viewer to directly display the content of the User-uploaded Visio file in IE.

For this requirement, we need to divide it into two parts:

1. Stores and reads the Visio file database and downloads it in Asp. Net.

2. Use the Visio Viewer provided by Microsoft and use this Object in HTML to call the Visio diagram.

For the first feature. First, you must upload files. During file upload, we generally need to record three contents: the Content Type, file name, and binary Content of the file. The functional code used to upload files to the database is simple.

Next, let's talk about the download function. We will create a new ViewFile. aspx file, and then write the following in the background code:

Protected void Page_Load (object sender, EventArgs e) {var p = Mgr. getprocpolicyid (Request. queryString ["id"]); Page. response. clear (); Page. response. contentType = p. fileContentType; // content type Page. response. addHeader ("Content-Disposition", "attachment; FileName =" + p. fileName); // file name Page. response. binaryWrite (p. processFile. toArray (); // File Content Page. response. end ();}

OK, that's simple. Now we only need to run the program, and then input ViewFile. aspx in the Url? If id = 6, you can read and download the Visio file with ID = 6.

Next, let's talk about the call of the Visio Viewer and compile a new page named VisioView. aspx,

Protected void Page_Load (object sender, EventArgs e) {StringBuilder sb = new StringBuilder (); sb. append ("<object classid = clsid: 279D6C9A-652E-4833-BEFC-312CA8887857 id = vviewer"); sb. append ("codebase = http://download.microsoft.com/download/4/5/2/452f8090-413f-408f-83c0-edd66db786ee/vviewer.exe Width = 100% Height = 600>"); sb. append ("<param name = SRC value =" + "http: // localhost: 2303/VisioFile. aspx? Id = 6 "+"> "); sb. append ("<param name = HighQualityRender value = 1>"); sb. append ("<param name = BackColor value = #000000>"); sb. append ("<param name = PageColor value = #000000>"); sb. append ("<param name = PageVisible value = 1>"); sb. append ("<param name = AlertsEnabled value = 1>"); sb. append ("<param name = ContextMenuEnabled value = 1>"); sb. append ("<param name = GridVisible value = 1>"); sb. append ("<param name = PropertyDialogEnabled value = 1>"); sb. append ("<param name = ScrollbarsVisible value = 1>"); sb. append ("<param name = ToolbarVisible value = 1>"); sb. append ("<param name = CurrentPageIndex value = 1>"); sb. append ("<param name = Zoom value =-1>"); sb. append ("</object>"); lvisio. text = sb. toString (); // here is a Literal control}

The code in this place is correct, but when we run the asp.net page, the error "Microsoft Office Visio Viewer cannot load the specified URL or file." appears .",

If the Visio file is downloaded normally, the src parameter is correct! What is the cause of this? After a simple study, I found it was a Bug in the Visio Viewer. This control only knows the url with the suffix of the Visio format, the File URL here is VisioFile. aspx? Id = 6. In this case, the Visio Viewer thinks that it is not a Visio file, so it does not load the content.

How can this problem be solved? There are several methods:

1. Create an httphandler for. ASD, and specify the class for interpreting the. ASD format, so that the URL will be changed to the XXX. ASD format.

2. Add a boring parameter: xx =. sealing. In this way, the Visio Viewer assumes that the path is a Visio file and loaded.

I used the second solution and modified the Code in line 6th:

Sb. Append ("<param name = SRC value =" + "http: // localhost: 2303/VisioFile. aspx? Id = 6 "+" & xx =. ASD> ");

OK. The Visio stored in the database can be normally displayed in the Visio Viewer.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.