在MSDN中看到这段代码,但执行有错误,怎么改正。
Imports EnvDTEPublic Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim soln As Solution = DTE.Solution
Dim prj As Project
Dim prjItem As ProjectItem
Dim ItemOp As ItemOperations
Dim savePath As String ' Create a new text document.
ItemOp = DTE.ItemOperations
ItemOp.NewFile("General\Text File", "Some name", _
EnvDTE.Constants.vsViewKindTextView) ' Set variables for proj and proj item names.
prj = soln.Item(1)
prjItem = prj.ProjectItems.Item(1)
savePath = "C:\UserFiles\KempB\" & prjItem.Name
MsgBox(savePath) If ItemOp.IsFileOpen(savePath) = True Then
MsgBox("The saved document is open.")
Else
MsgBox("The saved document is not open.")
End If prjItem.Save(savePath) If ItemOp.IsFileOpen(savePath) = True Then
MsgBox("The saved document is open.")
Else
MsgBox("The saved document is not open.")
End If
End Sub
End Class提示的错误是Dim soln As Solution = DTE.Solution 和 ItemOp = DTE.ItemOperations,错误信息对非共享成员的引用要求对象引用。
以上怎么解决,如果用c#,该怎么写。
Imports EnvDTEPublic Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim soln As Solution = DTE.Solution
Dim prj As Project
Dim prjItem As ProjectItem
Dim ItemOp As ItemOperations
Dim savePath As String ' Create a new text document.
ItemOp = DTE.ItemOperations
ItemOp.NewFile("General\Text File", "Some name", _
EnvDTE.Constants.vsViewKindTextView) ' Set variables for proj and proj item names.
prj = soln.Item(1)
prjItem = prj.ProjectItems.Item(1)
savePath = "C:\UserFiles\KempB\" & prjItem.Name
MsgBox(savePath) If ItemOp.IsFileOpen(savePath) = True Then
MsgBox("The saved document is open.")
Else
MsgBox("The saved document is not open.")
End If prjItem.Save(savePath) If ItemOp.IsFileOpen(savePath) = True Then
MsgBox("The saved document is open.")
Else
MsgBox("The saved document is not open.")
End If
End Sub
End Class提示的错误是Dim soln As Solution = DTE.Solution 和 ItemOp = DTE.ItemOperations,错误信息对非共享成员的引用要求对象引用。
以上怎么解决,如果用c#,该怎么写。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货