Converting Visio files in ASP.NET
page 3 of 5
by Jason N. Gaylord
Average Rating: 
Views (Total / Last 10 Days): 34496/ 73

Section 2: Creating the custom Visio.dll file
The next thing to do is to create the custom .dll library to use in your project(s). We start off by importing the new library. Then, by using a class browser, we can find that utilizing the Application class we can open a file and export the file as a particular type.

1:    Imports VisioDotNet
3:    Namespace Utilities
5:        Public Class Visio
7:            Public Sub SaveFile(infile as String, outfile as String)
8:                Dim app as New Application
10:               app.Documents.Open(infile)
11:               app.ActiveWindow.Page.Export(outfile)
12:               app.Close()
13:           End Sub
15:       End Class
17:   End Namespace
After creating the vb file, we can then compile:
vbc /t:library /r:System.dll,VisioDotNet.dll Visio.vb /out:Utilities.Visio.dll
Don't forget that we need to give the proper access to start Visio on the server. Even though this is done silently, the process still needs access. We will accomplish this in the next section.

View Entire Article

User Comments

Title: programmer   
Name: Mary
Date: 2009-11-09 10:43:43 AM
I need to use to present visio documents on the intranet here at work. Most people do not have visio or visio viewer on their machines. Will this code convert and display the visio in jpg on the server these people?
Title: Having mutiple pages in one .vsd file   
Name: AJIT
Date: 2008-10-15 8:51:22 AM
i have multiple pages in one .vsd so i want to save all of them as .jpg

so pl help me
Title: code hangs at   
Name: mittu
Date: 2008-05-22 11:47:47 PM
i have a code which exports to html.but the code hangs at addon command
any help
Name: Haffees
Date: 2007-04-27 7:19:59 AM
Which was imports function for RegistryKey
Title: Imports error   
Name: h12
Date: 2006-06-26 1:44:00 PM
When importing the VisioDotNet, the compiler shows some error and also there is error in the Application that the compiler cannot resolved. What should I do in such case?
Title: Dialogue Holding Up Automation   
Name: Nate
Date: 2006-02-02 12:47:43 PM
I ran into the problem where Visio would prompt for a Cross-Functional Conversion and it was holding up the automation. What I had to do was this to stop it from prompting:

I found a way to stop the dialogues for the Visio automation.


Disable: Enable Microsoft Visual Basic for Applications
Disable: Enable COM Add-ins
Disable: Enable Automation Events

Click Macro Security: Set to Very High

The dialogue is an add in OR an Automation Event. Either way I disabled what I could and it worked.

Title: C++ COM version   
Name: Subhash
Date: 2006-01-03 2:16:36 AM
I am trying to load a vsd file and make changes to it and saving back to html
Can anyone please help me with C++ version in COM.

Title: Re: 'Text' is not a member of 'System.Web.UI.HtmlControls.Html   
Name: Subhash
Date: 2005-12-05 4:32:22 AM

I reinstalled Visio 2003.. Which solved my problem with invalid access to memory location

Title: Re: Argh!   
Name: Jason
Date: 2005-11-14 10:51:45 AM
Sounds like your issues are a bit deeper. I have helped 2 others having an issue and it ended up being their PCs needed a reformat because VS.NET was corrupted. Also, make sure you have the following:

-Visio 2003
-.NET Framework 1.1
-Account credentials with permission to run Visio 2003
-Read/Write permissions to your "Output" folder (Unless importing to SQL)
Title: 'Text' is not a member of 'System.Web.UI.HtmlControls.Html   
Name: Subhash
Date: 2005-11-12 9:09:10 AM
Title: Re: Argh!   
Name: Technohig
Date: 2005-08-05 10:16:19 AM
DLL Hell. Dll was registered at assembly location for some reason. Had to reboot to safe mode to kill said dll. Now it is complaining that 'Text' is not a member of 'System.Web.UI.HtmlControls.HtmlInputFile'. Assuming I get this fixed and then it chokes at '"OutputFile" is not defined, can I assume the problem is at the asp:button line?
Title: Re: Argh!   
Name: Jason N. Gaylord
Date: 2005-08-03 1:21:02 PM
The Utilities.Visio.dll file should go in the bin folder for your web application.
Title: Re: Argh!   
Name: Technohig
Date: 2005-08-03 12:48:20 PM
Yes, Visio 2003; yes permissions out the wa-zoo. Doe the markup for the web.config file change when it is directed at a specific site, rather than the whole web server?
Title: RE: Argh!   
Name: Jason N. Gaylord
Date: 2005-08-02 3:15:50 PM
Are you using Visio 2003? You must make sure that the web server that you are using this with has this installed. It needs to use the DLLs that are contained within Visio 2003
Title: Argh!   
Name: Technohig
Date: 2005-08-02 2:12:09 PM
This would be great if it worked! I get a complilation error everytime I browse the website where convert.aspx is the default page--saying Utilities.Visio is not defined. Where does the Utilities.Visio dll go? (fails specifically at line: Dim doc As New Utilities.Visio)
Title: Continuing Interop Problems   
Name: Corey Alguire
Date: 2005-04-25 3:46:20 PM
Well, I added the user I am impersonating to the local admin group. I also made sure that user plus Network Service and the anonymous users for IIS and ASPNET have access to the DCOM objects. So now I no longer get access denied errors or errors about registry keys. However, I still get the same Server execution error. It happens on the line that instantiates a new instance of the application. I can see from TaskManager and from entries in a File Monitor app I use that Visio is starting up. In fact, the instance is spawned and never closes because of the crash. I just don't have any idea why this is failing. *Deeply puzzled and very frustrated.*
Title: Re: Error Found!   
Name: Jason N. Gaylord
Date: 2005-04-18 4:17:50 PM
I wrote this assuming that it would run as a web app running under an Admin account. If this isn't the case, you can add permissions to the registry key that it is having difficulty accessing. Have you tried that? Just be careful when dealing with the registry.
Title: Re: Error Found!   
Name: Corey
Date: 2005-04-14 5:43:10 PM
I actually have had exactly the same problem. I seems to be related to the permissions of the user. If I use an administrator login, the application works fine. But if I use the local account I set up for the job (just a standard user account), I get the "Server Execution Failed" exception.

Checking the Application Event Log, I find entries about a missing registry key (which is not actually missing, but might be inaccessible) and about a failure of the Windows Installer. From the user's standpoint, the app just appears to hang. I am honestly stumped about how to make this work for me, though- I can't just leave it running with the admin credentials stored in plain text. And I don't want to run it under and admin account anyway.
Title: RE: Error Found !   
Name: Jason N. Gaylord
Date: 2005-03-03 12:01:36 PM
Are you using Visio 2003? You must make sure that the web server that you are using this with has this installed. It needs to use the DLLs that are contained within Visio 2003. That error message is very vague and could be caused by not having Visio 2003 on the server or by not having the proper permissions.
Title: Error Found !   
Name: BD
Date: 2005-03-03 11:57:48 AM
I got a problem like...(error at line 9)

Server execution failed
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Server execution failed

Source Error:

Line 7:
Line 8: Public Sub SaveFile(ByVal infile As String, ByVal outfile As String)
Line 9: Dim app As New VisioDotNet.Application
Please tell me how to correct this. Thank You.
Title: RE[4]: Terminate the Process   
Name: Aleks
Date: 2004-08-27 10:55:43 AM
Jason, I found a way "around it", you can say. Here is the code that will output a multi-page visio to html:

public void SaveFile(string infile, string outfile)
Application app = new Application();

app.Addons.get_ItemU("SaveAsWeb").Run("/quiet=True /target=" + outfile);

A similar statement in VB will look something like this:

Application.Addons("SaveAsWeb").Run "/quiet=True /target=" + outfile

Thanks for all your help.
Title: RE[3]: Terminate the Process   
Name: Jason
Date: 2004-08-26 9:22:46 PM
I haven't tried exporting to HTML. I'd almost assume that you can either loop through the pages or that there is an attribute somewhere. If I get a chance sometime soon, I'll look into it.
Title: RE[2]: Terminate the Process   
Name: Aleks A
Date: 2004-08-26 5:21:28 PM
Yeah, that did the trick, Jason.

Any suggestions on exporting multipage visio documents? I think I have to iterate through the pages collection, the problem is, how would I combine all those pages into a single html document (eg export as html)? Any thoughts? When exporting to html from visio itself, it automatically assumes that all pages need to be exported, hence, it works perfectly, but only exports the active page using your method.
Title: RE: Terminate the Process   
Name: Jason
Date: 2004-08-20 11:45:04 PM
I haven't tested this, but, I'm assuming if you open Visio and allow the macros to run every time, it shouldn't stall in this process above.
Title: Terminate the Process   
Name: Aleks
Date: 2004-08-20 4:33:07 PM
Here is the C# version:

public void SaveFile(string infile, string outfile)
Application app = new Application();


Make sure you quit the application, or you'll spawn new process every time!

Anyone know how to bypass the macro prompt in visio? I can't find it...

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-05-28 10:03:01 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search