我在使用winform打开绘图时遇到问题。我得到的错误说NullReferenceException未处理并突出显示该路径。任何帮助表示赞赏。感谢
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 :(得分:2)
System.Diagnostics.Process.Start("explorer.exe c:\\");
这可以帮助
答案 1 :(得分:1)
为什么你会得到NullReferenceException
有两种可能性GetOpenDocSpec
的内容将无法正常工作使用调试器检查swApp == null应该很容易。使用汽车或观察窗口,将鼠标悬停在变量上,从命令窗口转换?swApp == null等。