Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to use VISIO2003 in C#

Posted on 2006-11-30
8
Medium Priority
?
737 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses

971 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