Solved

How to use VISIO2003 in C#

Posted on 2006-11-30
8
720 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now