为什么Virtual Basic说它无法访问该文件?

时间:2016-05-11 08:44:32

标签: vb.net file save

我正在创建一个可靠的边缘宏,可以同时将三个不同类型的3D文件保存在实心边缘 不过,我是vb.net的新手,我有些困难。

当我运行程序时,第一个弹出窗口显示"此文件已存在,是否要覆盖它?"。

下一个弹出窗口显示"无法访问此文件"然后程序停止。
为什么vb.net无法访问该文件?它在背景中以坚实的边缘打开。

Imports System.Runtime.InteropServices
    Public Class Form1

        Private Sub saveBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles saveBtn.Click
            Dim objApplication As SolidEdgeFramework.Application = Nothing
            Dim objDocument As SolidEdgeFramework.SolidEdgeDocument = Nothing
            Dim objPropertySets As SolidEdgeFramework.PropertySets = Nothing
            Dim objProperties As SolidEdgeFramework.Properties = Nothing
            Dim objProperty As SolidEdgeFramework.Property = Nothing
            Dim FileName As String
            Dim i, j As Integer
            Dim NewFileName1 As String
            Dim NewFileName2 As String
            Dim NewFileName3 As String
            Dim Extensions(2) As String
            Extensions(0) = ".step"
            Extensions(1) = ".x_t"
            Extensions(2) = ".igs"
            Try
                objApplication = Marshal.GetActiveObject("SolidEdge.Application")
                objDocument = objApplication.ActiveDocument
                objPropertySets = objDocument.Properties
                For i = 1 To objPropertySets.Count
                    objProperties = objPropertySets.Item(i)
                    For j = 1 To objProperties.Count
                        objProperty = objProperties.Item(j)
                    Next
                Next
                FileName = objProperty.Name
                NewFileName1 = FileName & Extensions(0)
                NewFileName2 = FileName & Extensions(1)
                NewFileName3 = FileName & Extensions(2)
                objDocument.SaveAs("C:\Folder", NewFileName1)
                objDocument.SaveAs("C:\Folder", NewFileName2)
                objDocument.SaveAs("C:\Folder", NewFileName3)
                'objDocument.SaveAs(NewFileName1)
                'objDocument.SaveAs(NewFileName2)
                'objDocument.SaveAs(NewFileName3)
            Catch ex As Exception
                txt.Text = "           Error"
            Finally
                If Not (objDocument Is Nothing) Then
                    Marshal.ReleaseComObject(objDocument)
                    objDocument = Nothing
                End If
                If Not (objApplication Is Nothing) Then
                    Marshal.ReleaseComObject(objApplication)
                    objApplication = Nothing
                End If

            End Try
        End Sub
        End Class

0 个答案:

没有答案