Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Each time I try to load Windows UserControl from the Solution explorer into the IDE, I get this error. I can handle this in ASP.NET and Windows form but this has been a lot of headache in Windows UserControl. Please what can I do? See below for details
Hide Call Stack 
 
at System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement)
at System.Drawing.Image.FromFile(String filename)
at COE_Information_Systems.uccStudentBioData.Clear() in C:\Users\Josh\Documents\Visual Studio 2015\Projects\COE_Information_Systems\COE_Information_Systems\uccStudentBioData.cs:line 105
at COE_Information_Systems.uccStudentBioData.uccStudentBioData_Load(Object sender, EventArgs e) in C:\Users\Josh\Documents\Visual Studio 2015\Projects\COE_Information_Systems\COE_Information_Systems\uccStudentBioData.cs:line 695
at System.Windows.Forms.UserControl.OnLoad(EventArgs e)
at System.Windows.Forms.UserControl.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at System.Windows.Forms.Form.ControlCollection.Add(Control value)
at System.Windows.Forms.Design.ControlDesigner.DesignerControlCollection.Add(Control c)
This is my line 105 in the usercontrol code behind
C#
this.picStudentPhoto.Image = Image.FromFile(Application.StartupPath + "\\StudentImages\\DefaultStudent.png");
This is my line 695 in the usercontrol code behind
C#
void Clear()
{
            //Clear and re-initilaize all controls and variables
      

            this.picStudentPhoto.Image = Image.FromFile(Application.StartupPath + "\\StudentImages\\DefaultStudent.png");//Line 105
            this.picViewUTME.Image = Image.FromFile(Application.StartupPath + "\\StudentImages\\DocDefault.png");

}


private void uccStudentBioData_Load(object sender, EventArgs e)
{
            InitilizeCntrls();
            this.Clear();//line 695
            FillStudentDataGridView();
}


What I have tried:

Noting yet cause I can't step through the code
Posted
Updated 27-Nov-18 1:26am
v2
Comments
Richard MacCutchan 27-Nov-18 7:51am    
Could be because Application.StartupPath is not the same in the IDE as in the final running application. It is probably a better idea to add the image to your resources.
Member 2575377 28-Nov-18 8:41am    
Richard!What sample code can replace this please>>"Application.StartupPath "? I Need a quick fix somebody. But line 105 is giving similar error.What am I doing wrong in these scenarios? "Application.StartupPath i.e Bin folder VS.NET 2015" contains an image folders with .png extension in and sql server database field.

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