2011-09-09 100 views
0

我在打开图形时遇到了麻烦。我得到的错误说NullReferenceException是未处理的,并突出显示了该路径。任何帮助表示赞赏。由于在C中打开文件路径#

private void button2_Click(object sender, EventArgs e) 
    { 
     //Open Solidworks Drawing 
     ModelDoc2 swModel = default(ModelDoc2); 
     DocumentSpecification swDocSpecification = default(DocumentSpecification); 
     string sName = null; 
     long longstatus = 0; 
     long longwarnings = 0; 
     // Drawing document path and name   
     swDocSpecification = (DocumentSpecification)swApp.GetOpenDocSpec("C:\\location\\????.slddrw");//File Location 
     sName = swDocSpecification.FileName; 
     // Sheet name   
     swDocSpecification.SheetName = "BOM"; //Open to the BOM sheet 
     swDocSpecification.DocumentType = (int)swDocumentTypes_e.swDocDRAWING; 
     swDocSpecification.ReadOnly = true; 
     swDocSpecification.Silent = false; 
     // Open the specified sheet in the specified drawing document   
     swModel = swApp.OpenDoc7(swDocSpecification); 
     longstatus = swDocSpecification.Error; 
     longwarnings = swDocSpecification.Warning; 
    } 
+0

using SolidWorks.Interop.sldworks; –

+1

什么是通路?为什么你有这样的“文件路径”(或简单的路径):C:\\ location \\ ????。slddrw!? –

+0

我主要想知道我是否正确引用通路 –

回答

1

有两种可能性,为什么你得到的NullReferenceException

  1. swApp为空,并呼吁任何计有GetOpenDocSpec将无法​​正常工作
  2. GetOpenDocSpec中的某些内容不是按照它应该的方式编写的,它没有执行正确的检查。所以它抛出一个空例外

它应该很容易检查是否swapp == null使用您的调试器。使用汽车或监视窗口,将鼠标悬停在变量上,命令窗口中的?swApp == null等。

2
System.Diagnostics.Process.Start("explorer.exe c:\\"); 

这可以帮助

+0

其实那工作谢谢 –

相关问题