IWorkspaceFactory factory = new CadWorkspaceFactoryClass (); IWorkspace workspace = factory.OpenFromFile(fileName, 0); // Throw exception
Hello, I had the same issue with reading DWG files using custom SOE and managed to solve it. It turned out that the OpenFromFile() method must be called with directory path not the file path as argument.
So instead of:
IWorkspace workspace <SPAN class="operator token">=</SPAN> factory<SPAN class="punctuation token">.</SPAN><SPAN class="token function">OpenFromFile</SPAN><SPAN class="punctuation token">(</SPAN>fileName<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
Try with this:
<SPAN class="keyword token">string</SPAN> directoryName <SPAN class="operator token">=</SPAN> fileName<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Substring</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> fileName<SPAN class="punctuation token">.</SPAN><SPAN class="token function">LastIndexOf</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'\\'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> IWorkspace workspace <SPAN class="operator token">=</SPAN> factory<SPAN class="punctuation token">.</SPAN><SPAN class="token function">OpenFromFile</SPAN><SPAN class="punctuation token">(</SPAN>directoryName<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Any news?????
Never use New to create an instance of a singleton object like a workspace factory. Always use the Activator class. Also, is this a standalone application? If so, are you binding to a product then checking out a license before running this code?
Type factoryType = Type.GetTypeFromProgID( "esriDataSourcesFile.CadWorkspaceFactory"); System.Object obj = Activator.CreateInstance(factoryType); IWorkspaceFactory factory = obj as IWorkspaceFactory; IFeatureWorkspace workspace = (IFeatureWorkspace)factory.OpenFromFile(dgnFilePath, 0);
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.