开发者

Opening a File Pathway in C#

开发者 https://www.devze.com 2023-04-03 16:12 出处:网络
I am having trouble with winform opening a drawing. The error I am getting says NullReferenceException was unhandled and is highlighting the pathway. any help is appreciated. Thanks

I am having trouble with winform opening a drawing. The error I am getting says NullReferenceException was unhandled and is highlighting the pathway. any help is appreciated. Thanks

private void button2_Click(object sender, EventArgs e)
    {
        //Open Solidworks Drawing
        ModelDoc2 swMod开发者_如何学Pythonel = 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;
    }


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

this can help


There are two possibilities as to why you're getting the NullReferenceException

  1. swApp is null and calling anything inlcuding GetOpenDocSpec won't work
  2. Something inside GetOpenDocSpec isn't written the way it supposed to, and its not doing the correct checking. And so its throwing a null exception

It should pretty easy to just check if swApp == null using your debugger. Using the autos or watch windows, hovering over the variable, ?swApp == null from the command window, etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号