Solved

How to use VISIO2003 in C#

Posted on 2006-11-30
8
729 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

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

Suggested Solutions

Title # Comments Views Activity
How to repeat the data 4 44
ASP.NET data base connection 35 95
async questions 5 50
How do I "share" on social sites? 2 40
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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

710 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