2 Replies - 1355 Views - Last Post: 12 October 2012 - 07:42 PM Rate Topic: -----

#1 cltp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-October 12

VB.NET ProcessStartInfo: how to override the default file association

Posted 12 October 2012 - 03:56 PM

My VB.NET program needs to open TrueView to display .dwg files. The program works fine if user only has TrueView, but not with people who have both TrueView and AutoCad and have associated their .dwg with AutoCad. How do I override the default file association without changing the registry so my program only open TrueView?

 Public Sub DownloadDiagram(ByVal DiagramID As Integer)
        Dim DatabaseName As String = "Diagrams"

        Dim buffer As Byte() = Nothing

        Dim sfilepath As String
        Dim strsql As String

        strsql = "SELECT Diagram FROM DAJobsDiagram WHERE DiagramID =  '" & DiagramID & "'"

        buffer = dhSQL.ExecuteScalar(DatabaseName, strsql)
        sfilepath = System.IO.Path.GetTempFileName()
        System.IO.File.Move(sfilepath, System.IO.Path.ChangeExtension(sfilepath, ".dwg"))
        sfilepath = System.IO.Path.ChangeExtension(sfilepath, ".dwg")

        System.IO.File.WriteAllBytes(sfilepath, buffer)

        Dim act As Action(Of String) = New Action(Of String)(AddressOf OpenDiagramFile)
        act.BeginInvoke(sfilepath, Nothing, Nothing)
        
    End Sub

    Private Sub OpenDiagramFile(ByVal sFilePath)
      
       Using p As New System.Diagnostics.Process
          p.StartInfo = New System.Diagnostics.ProcessStartInfo(sFilePath)
               'I tried: p.StartInfo = New System.Diagnostics.ProcessStartInfo(appFile, sFilePath)
               'where appFile = "C:\Program Files\Autodesk\DWG TrueView\dwgviewr.exe"
               'It solves the problem of opening AutoCad, but it opens a new instance of TrueView each time.
               'It's nice if TrueView opens once and multilple windows for different drawings.
          p.Start()
          p.WaitForExit()
          System.IO.File.Delete(sFilePath)
            
        End Using
    End Sub

 

This post has been edited by AdamSpeight2008: 12 October 2012 - 04:31 PM


Is This A Good Question/Topic? 0
  • +

Replies To: VB.NET ProcessStartInfo: how to override the default file association

#2 CharlieMay  Icon User is online

  • This space intentionally left blank
  • member icon

Reputation: 1534
  • View blog
  • Posts: 4,933
  • Joined: 25-September 09

Re: VB.NET ProcessStartInfo: how to override the default file association

Posted 12 October 2012 - 04:52 PM

Not sure if this is what you're looking for but if I double-click a .txt file, it opens in notepad

If I do:
Process.Start("D:\Fields.txt")

It opens in notepad

However, I can also do
Process.Start("WordPad.exe", "D:\Fields.txt") and fields.txt opens in wordpad.
Was This Post Helpful? 0
  • +
  • -

#3 cltp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-October 12

Re: VB.NET ProcessStartInfo: how to override the default file association

Posted 12 October 2012 - 07:42 PM

View PostCharlieMay, on 12 October 2012 - 04:52 PM, said:

Not sure if this is what you're looking for but if I double-click a .txt file, it opens in notepad

If I do:
Process.Start("D:\Fields.txt")

It opens in notepad

However, I can also do
Process.Start("WordPad.exe", "D:\Fields.txt") and fields.txt opens in wordpad.




You're right. If I specified the TrueViewr.exe, the program would open TrueView every time. However, I don't want new instance of TrueView created every time I open a drawing. If Trueview is running, the program shouldn't need to open a new TrueView instance for another drawing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1