Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to use VISIO2003 in C#

Posted on 2006-11-30
8
Medium Priority
?
734 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 1500 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

722 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