Solved

How to use VISIO2003 in C#

Posted on 2006-11-30
8
728 Views
Last Modified: 2010-05-18
Hello
I have a drawing in VISIO2003 in wich I placed some computer icons each one must have a Name and S/N.
How can I give those details by embedding VISIO2003 into C# or vice-versa, is there a way?

Any code examples will be much appreciated!

Thanks
Lioritshiran
0
Comment
Question by:liorb
  • 5
  • 3
8 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 18050117
You can link Visio to a database to do this, would that not be easier than trying to program it from .net ?
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 18050288
If you really want to program Visio, start here :

http://support.microsoft.com/kb/305199
0
 
LVL 1

Author Comment

by:liorb
ID: 18051927
ozymandias

How do I link Visio shapes to a database using C#?

I need some code examples please.

And the link you gave refers to visual basic I need C#.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:ozymandias
ID: 18052038
I haven't had a chance to test this but this is an example in c# :

using System;
using Microsoft.Office.Interop.Visio;

using visApp = Microsoft.Office.Interop.Visio.Application;
using visDoc = Microsoft.Office.Interop.Visio.Document;
using visShape = Microsoft.Office.Interop.Visio.Shape;
using visMaster = Microsoft.Office.Interop.Visio.Master;


namespace VisioTest{

      class Class1{
      

            [STAThread]
            static void Main(string[] args)
            {
                  
                  visApp app = new visApp();
                  visDoc doc = app.Documents.Add("");
                  visDoc visStencil = app.Documents.OpenEx(@"C:\Program Files\Microsoft Office\Visio11\1033\COMPS_M.vss", 4);
                  visMaster pcMaster = visStencil.Masters["PC"];
                  visShape pc = app.ActivePage.Drop(pcMaster, 50, 50);
                  pc.Text = "Computer Name : SerialNumber";
                  doc.SaveAs(@"c:\temp\test.vsd");


            }
      }
}


This would create a new visio doc and then add a PC shape from the Computer stencil and set its text to a name and serial number value.
To compile this as a project you would need to add a reference to the COM dll "Microsoft Visio 11 Type Library".
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 18052116
If you want to use data from a database to create objects on a page, do this :

Start a new Detailed Network Diagram.
Click on Tools -> Add ons -> Run Add on.
Select Import Data and click on OK.
Click on Next
Select ODBC for Type and click on Next
Set your database connection details and click on Next
Select which tabke columns to include and click on Next
Set any filters you need and click Next
Select the stencil master you want to represent each record in your data and click next
Select the field you want to appear as the shape label and click on next
Specify the unique ID field if there is one and click next
The shapes will be drawn and labelled on the page all you have to do is lay them out.

You can link to a database, or directly to active directory, and populate all the custom properties of your shape.
You can even set it so that if you edit the property of a shape it updates the database, so Visio can be used and an interface to the db.

For that run the Database Wizrd add on.




0
 
LVL 15

Accepted Solution

by:
ozymandias earned 500 total points
ID: 18052626
BTW, in my code above there is an error :

visShape pc = app.ActivePage.Drop(pcMaster, 50, 50);

should be

visShape pc = app.ActivePage.Drop(pcMaster, 1, 1);

50,50 places the shape way off the page.


0
 
LVL 1

Author Comment

by:liorb
ID: 18054672
ozymandias

First problem with your example -

The name office does not exist in the namespace Microsoft.
What should I do?
0
 
LVL 1

Author Comment

by:liorb
ID: 18054934
Sorry
I've managed to add the name Office

Still checking!!..
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# Gridview 1 64
tableview is not updating 1 28
Problem with SelectList in .NET MVC application 1 34
C# class library debugging - Breakpoint will not hit. 8 30
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question