Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi there, I am new to C# WinForm development.
I have a picturebox to preview solidworks(a CAD software) parts,
but this code cannot view the large-size files. For example, I can preview a 1,684k file smoothly. However, when I was trying to preview a 3,165k file the following EXCEPTION message poped up.
I don't know whether I express myself clearly, but please feel free to ask me if you have further questions. I can send my code to you for debugging.
Cheers!

--------------------My C# WinForm Code--------------------------------
C#
private void Preview_Click(object sender, EventArgs e)
{

    textBox3.Text = dataGridView1.SelectedCells[3].Value.ToString();
    string STORAGE_NAME = textBox3.Text;
    //Get the entity of file with nodes
    CompoundFile cf = new CompoundFile(STORAGE_NAME);
    //Get desired node
    CFStream st = cf.RootStorage.GetStream("PreviewPNG");
    //Convert: stream-array of bytes-to memory-to picturebox
    byte[] buffer = st.GetData();
    var ms = new MemoryStream(buffer.ToArray());
    pictureBox1.Image = Image.FromStream(ms);

}


--------------------Exception Details--------------------------------
OpenMcdf.CFItemNotFound was unhandled
  Message=Cannot find item [PreviewPNG] within the current storage
  Source=OpenMcdf
  StackTrace:
       at OpenMcdf.CFStorage.GetStream(String streamName)
       at CustomisedDesign.Form1.Preview_Click(Object sender, EventArgs e) in C:\Users\Bomiao\Documents\Visual Studio 2010\Projects\CustomisedDesign\CustomisedDesign\Form1.cs:line 519
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at CustomisedDesign.Program.Main() in C:\Users\Bomiao\Documents\Visual Studio 2010\Projects\CustomisedDesign\CustomisedDesign\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:
Posted
Updated 25-May-12 10:22am
v2

1 solution

It seems to be thrown by OpenMCDF. Are you using the latest version of it? Have you tried to extract the PreviewPNG stream with other methods (you might be able to open the file with 7zip as archive, and find the stream), or with other MCDF readers? The OpenMCDF might have an error, but you might happen to have a newer/different file format, than OpenMCDF reads.

I suggest you to include the source of it in your project, and step into it to see what's there.

About the format: http://www.openoffice.org/sc/compdocfileformat.pdf[^]
Might be also usefull: http://help.solidworks.com/2010/English/api/swdocmgrapi/SolidWorks.Interop.swdocumentmgr~SolidWorks.Interop.swdocumentmgr.ISwDMSheet2~GetPreviewPNGBitmapBytes.html[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900