|
hey there, im reasonably new to C# and im currently writing a backup application which im using as a learning resource.
My PC :-
Visual Studio 2005
.NET Framework 2
Component Factory Krypton Tools
Test PC :-
.Net Framework 2
==============================================
The Issue:
On the testing PC, im receiving this error:
============================================== -
System.NullReferenceException: Object reference not set to an instance of an object.
-
-
************** Exception Text **************
-
System.NullReferenceException: Object reference not set to an instance of an object.
-
at Backup.frmMain.ShowError(String title, String body)
-
at Backup.frmMain.Form1_Load(Object sender, EventArgs e)
-
at System.Windows.Forms.Form.OnLoad(EventArgs e)
-
at ComponentFactory.Krypton.Toolkit.KryptonForm.OnLoad(EventArgs e)
-
at System.Windows.Forms.Form.OnCreateControl()
-
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
-
at System.Windows.Forms.Control.CreateControl()
-
at System.Windows.Forms.Control.WmShowWindow(Message& m)
-
at System.Windows.Forms.Control.WndProc(Message& m)
-
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
-
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
-
at System.Windows.Forms.Form.WmShowWindow(Message& m)
-
at System.Windows.Forms.Form.WndProc(Message& m)
-
at ComponentFactory.Krypton.Toolkit.VisualForm.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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
-
-
-
************** Loaded Assemblies **************
-
mscorlib
-
Assembly Version: 2.0.0.0
-
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
-
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
-
----------------------------------------
-
Backup
-
Assembly Version: 1.0.0.0
-
Win32 Version: 1.0.0.0
-
CodeBase: file:///F:/Backup/Backup.exe
-
----------------------------------------
-
System.Windows.Forms
-
Assembly Version: 2.0.0.0
-
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
-
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
-
----------------------------------------
-
System
-
Assembly Version: 2.0.0.0
-
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
-
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
-
----------------------------------------
-
System.Drawing
-
Assembly Version: 2.0.0.0
-
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
-
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
-
----------------------------------------
-
ComponentFactory.Krypton.Toolkit
-
Assembly Version: 3.0.8.0
-
Win32 Version: 3.0.8.0
-
CodeBase: file:///F:/Backup/ComponentFactory.Krypton.Toolkit.DLL
-
==============================================
Now, I've copied all the Krypton DLL's into the runtime directory of the Backup application. but im not sure what in my code is causing this.
CODE:
============================================== -
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.Windows.Forms;
-
using System.IO;
-
using System.Threading;
-
using ComponentFactory.Krypton.Toolkit;
-
-
namespace Backup
-
{
-
-
public partial class frmMain : ComponentFactory.Krypton.Toolkit.KryptonForm
-
{
-
public int diff_x;
-
public int diff_y;
-
-
string USER_NAME = SystemInformation.UserName;
-
string DATE = Convert.ToString(System.DateTime.Now.Day + "-" + System.DateTime.Now.Month + "-" + System.DateTime.Now.Year);
-
-
string[,] UserDirs;
-
enum ext { dir, zip, exe, txt, pfd, xls, ppt, doc };
-
-
public frmMain()
-
{
-
UserDirs = new string[,]
-
{
-
{"Favorites", "C:\\Documents and Settings\\" + USER_NAME + "\\Favorites\\"},
-
{"Desktop", "D:\\USERDATA\\" + USER_NAME + "\\Desktop\\"},
-
{"Macros", "C:\\Documents and Settings\\" + USER_NAME + "\\Application Data\\Microsoft\\templates\\"},
-
{"Backups", "H:\\" + USER_NAME + " Backups\\"}
-
};
-
-
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
-
InitializeComponent();
-
this.hdrTitleBar.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ButtonDown);
-
}
-
-
private long FreeHomeDriveSpace()
-
{
-
return 209715200 - (CalculateSize(new DirectoryInfo("H:\\")));
-
}
-
-
private bool CopyRecursiveFiles(DirectoryInfo d, string DestinationDirectory, bool CreateEmptyDir,string Extension)
-
{
-
-
try
-
{
-
if (CalculateSize(d) > FreeHomeDriveSpace())
-
{
-
ShowError("Error","You have insufficient space for copying");
-
return false;
-
}
-
else
-
{
-
FileInfo[] fis = d.GetFiles("*." + Extension);
-
-
// Create the destination directory, if CreateEmptyDir or contains files
-
-
if ((fis.Length > 0) || (CreateEmptyDir))
-
Directory.CreateDirectory(DestinationDirectory);
-
-
foreach (FileInfo fi in fis)
-
{
-
if(!File.Exists(DestinationDirectory + "\\" + fi.Name)) fi.CopyTo(DestinationDirectory + "\\" + fi.Name);
-
}
-
-
// Recursive copy children dirs
-
DirectoryInfo[] dis = d.GetDirectories();
-
-
foreach (DirectoryInfo di in dis)
-
{
-
CopyRecursiveFiles(di, DestinationDirectory + "\\" + di.Name, CreateEmptyDir, Extension);
-
}
-
-
Thread t = new Thread(Restore);
-
t.Start();
-
-
Thread h = new Thread(HDrive);
-
h.Start();
-
}
-
-
-
}
-
catch
-
{
-
return false;
-
}
-
-
return true;
-
}
-
-
private bool RestoreRecursiveFiles(DirectoryInfo d, string DestinationDirectory, bool CreateEmptyDir, string Extension)
-
{
-
-
try
-
{
-
FileInfo[] fis = d.GetFiles("*." + Extension);
-
-
// Create the destination directory, if CreateEmptyDir or contains files
-
-
if ((fis.Length > 0) || (CreateEmptyDir))
-
Directory.CreateDirectory(DestinationDirectory);
-
-
foreach (FileInfo fi in fis)
-
{
-
if (!File.Exists(DestinationDirectory + "\\" + fi.Name)) fi.CopyTo(DestinationDirectory + "\\" + fi.Name);
-
}
-
-
// Recursive copy children dirs
-
DirectoryInfo[] dis = d.GetDirectories();
-
-
foreach (DirectoryInfo di in dis)
-
{
-
CopyRecursiveFiles(di, DestinationDirectory + "\\" + di.Name, CreateEmptyDir, Extension);
-
}
-
-
Thread t = new Thread(Restore);
-
t.Start();
-
-
Thread h = new Thread(HDrive);
-
h.Start();
-
-
}
-
catch (Exception CopyErr)
-
{
-
return false;
-
}
-
-
return true;
-
}
-
-
private void BackupDir(DirectoryInfo Dir)
-
{
-
-
#region # Today Backup Check
-
if (!Directory.Exists(UserDirs[3,1] + DATE))
-
{
-
try
-
{
-
Directory.CreateDirectory("H:\\" + USER_NAME + " Backups\\" + DATE);
-
}
-
-
catch (Exception DateEx)
-
{
-
ShowError("Error", DateEx.ToString());
-
}
-
}
-
#endregion
-
-
}
-
-
-
-
/*-----------------------------------------------
-
* Event : CalculateSize
-
* Purpose : Calculates the size of a given directory
-
* Args :
-
* DirectoryInfo (object)
-
*
-
* Returns : Long
-
* Author : Brendan Scarvell
-
* Date : 03/02/08
-
* History :
-
* -----------------------------------------------
-
* 03/02/08 Created
-
-----------------------------------------------*/
-
public long CalculateSize(DirectoryInfo d)
-
{
-
FileInfo[] files;
-
files = d.GetFiles("*");
-
long UnFormatedSize = 0L; // need to define this variable
-
foreach (FileInfo file in files)
-
{
-
UnFormatedSize += file.Length; // no need for any conversions here
-
}
-
DirectoryInfo[] dirs = d.GetDirectories("*");
-
foreach (DirectoryInfo dir in dirs)
-
{
-
UnFormatedSize += CalculateSize(dir); // need to add to UnFormatedSize
-
}
-
return UnFormatedSize;
-
}
-
-
-
private void kryptonButton1_Click(object sender, EventArgs e)
-
{
-
Application.Exit();
-
}
-
-
/*-----------------------------------------------
-
* Event : GetUnit
-
* Purpose : Convert a value into a value
-
* Args :
-
* sender (object)
-
* e (EventArgs)
-
* Returns : Null
-
* Author : Brendan Scarvell
-
* Date : 03/02/08
-
* History :
-
* -----------------------------------------------
-
* 03/02/08 Created
-
-----------------------------------------------*/
-
private void GetUnit(ref string Size)
-
{
-
string[] units = new string[9] { "Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
-
double loop = Convert.ToDouble(Size);
-
int UnitPos = 0;
-
-
try
-
{
-
if (loop >= 1024)
-
{
-
while (loop >= 1)
-
{
-
if ((loop / 1024) >= 1)
-
{
-
loop = loop / 1024;
-
UnitPos++;
-
}
-
else
-
{
-
break;
-
}
-
}
-
}
-
Size = loop.ToString("F1") + " " + units[UnitPos];
-
}
-
-
catch (Exception cv)
-
{
-
MessageBox.Show(cv.ToString());
-
}
-
-
}
-
-
private void Form1_Load(object sender, EventArgs e)
-
{
-
-
-
#region # StartUp Checks
-
-
bool StartThreads = true;
-
-
// Check that all directories and paths exist
-
-
if (!Directory.Exists("H:\\"))
-
{
-
ShowError("Error", "Home Drive doesn't exist. Please contact the InfoService Center to have this resolved");
-
StartThreads = false;
-
}
-
-
if (!Directory.Exists("H:\\" + USER_NAME))
-
{
-
try
-
{
-
Directory.CreateDirectory("H:\\" + USER_NAME);
-
}
-
-
catch (Exception ex)
-
{
-
StartThreads = false;
-
ShowError("Error", ex.ToString());
-
}
-
}
-
-
-
#endregion
-
-
-
if (StartThreads)
-
{
-
Thread t = new Thread(HDrive);
-
t.Start();
-
-
Thread r = new Thread(Restore);
-
r.Start();
-
}
-
-
-
#region # Backup Methods
-
/** Load Backup methods **/
-
-
ToolStripMenuItem backUpDesktopMenu = new ToolStripMenuItem();
-
ToolStripMenuItem backUpFavsMenu = new ToolStripMenuItem();
-
ToolStripMenuItem backUpMacrosMenu = new ToolStripMenuItem();
-
ToolStripSeparator childSeperator = new ToolStripSeparator();
-
ToolStripMenuItem backUpAllMenu = new ToolStripMenuItem();
-
-
backUpDesktopMenu.Text = "Desktop";
-
backUpDesktopMenu.Image = global::Backup.Properties.Resources.monitor;
-
backUpDesktopMenu.Click += new EventHandler(this.BackupDesktop_Click);
-
-
backUpFavsMenu.Text = "Favorites";
-
backUpFavsMenu.Image = global::Backup.Properties.Resources.world;
-
backUpFavsMenu.Click += new EventHandler(this.BackupFavs_Click);
-
-
backUpMacrosMenu.Text = "Macros";
-
backUpMacrosMenu.Image = global::Backup.Properties.Resources.script_code;
-
backUpMacrosMenu.Click += new EventHandler(this.BackupMacros_Click);
-
-
backUpAllMenu.Text = "Everything";
-
backUpAllMenu.Image = global::Backup.Properties.Resources.tick;
-
backUpAllMenu.Click += new EventHandler(this.BackupAll_Click);
-
-
cmBackup.Items.AddRange(new ToolStripItem[] { backUpDesktopMenu, backUpFavsMenu, backUpMacrosMenu, childSeperator, backUpAllMenu });
-
-
#endregion
-
-
}
-
-
private void DesktopMenu_Click(object sender, System.EventArgs e)
-
{
-
ContextMenu x = (ContextMenu) sender;
-
bool msgbox;
-
-
DialogResult Restore = MessageBox.Show("Are you sure you wish to restore your Desktop Icons from '" + x.Date.ToString() + "'?", "Restore", MessageBoxButtons.YesNo);
-
-
if (Restore == DialogResult.Yes)
-
{
-
msgbox = RestoreRecursiveFiles(new DirectoryInfo(UserDirs[3, 1] + "\\" + x.Date.ToString() + "\\Desktop\\"), UserDirs[1,1],true,"*");
-
-
if (msgbox) MessageBox.Show("Desktop Icons successfully restored");
-
}
-
}
-
-
private void AllMenu_Click(object sender, System.EventArgs e)
-
{
-
ContextMenu x = (ContextMenu)sender;
-
-
DialogResult Restore = MessageBox.Show("Are you sure you wish to restore your Desktop Icons from '" + x.Date.ToString() + "'?", "Restore", MessageBoxButtons.YesNo);
-
-
if (Restore == DialogResult.Yes)
-
{
-
MessageBox.Show("Yes");
-
}
-
else
-
{
-
MessageBox.Show("no...");
-
}
-
-
}
-
-
private void FavsMenu_Click(object sender, System.EventArgs e)
-
{
-
ContextMenu x = (ContextMenu)sender;
-
bool msgbox;
-
-
DialogResult Restore = MessageBox.Show("Are you sure you wish to restore your Internet Favorites from '" + x.Date.ToString() + "'?", "Restore", MessageBoxButtons.YesNo);
-
-
if (Restore == DialogResult.Yes)
-
{
-
msgbox = RestoreRecursiveFiles(new DirectoryInfo(UserDirs[3, 1] + "\\" + x.Date.ToString() + "\\Favorites\\"), UserDirs[0,1],true,"*");
-
-
if (msgbox) MessageBox.Show("Internet Favorites restored successfully");
-
}
-
-
}
-
-
private void MacrosMenu_Click(object sender, System.EventArgs e)
-
{
-
ContextMenu x = (ContextMenu)sender;
-
bool msgbox;
-
-
DialogResult Restore = MessageBox.Show("Are you sure you wish to restore your Macros from '" + x.Date.ToString() + "'?", "Restore", MessageBoxButtons.YesNo);
-
-
if (Restore == DialogResult.Yes)
-
{
-
msgbox = RestoreRecursiveFiles(new DirectoryInfo(UserDirs[3, 1] + "\\" + x.Date.ToString() + "\\Favorites\\"), UserDirs[0, 1], true, "*");
-
-
if (msgbox) MessageBox.Show("Macros restore successfully");
-
}
-
-
}
-
-
/** Restore **/
-
private void Restore()
-
{
-
ContextMenuStrip cmRestore = new ContextMenuStrip();
-
cmdRestore.ContextMenuStrip = cmRestore;
-
-
DirectoryInfo R = new DirectoryInfo(UserDirs[3,1]);
-
int j = 0; // Used to count how many entries there are
-
-
try
-
{
-
foreach (DirectoryInfo d in R.GetDirectories("*.*"))
-
{
-
-
ToolStripMenuItem parentmnu = new ToolStripMenuItem();
-
ContextMenu childDesktop = new ContextMenu();
-
ContextMenu childFavs = new ContextMenu();
-
ContextMenu childMacros = new ContextMenu();
-
ToolStripSeparator childSeperator = new ToolStripSeparator();
-
ContextMenu childAll = new ContextMenu();
-
bool DisableAll = false; // Set as true if one or more back up methods are missing
-
-
// parent Item
-
parentmnu.Text = d.Name.ToString();
-
parentmnu.Image = global::Backup.Properties.Resources.folder;
-
-
// Child Items
-
childDesktop.Text = "Desktop";
-
childDesktop.Image = global::Backup.Properties.Resources.monitor;
-
childDesktop.Date = parentmnu.Text;
-
childDesktop.Click += new EventHandler(this.DesktopMenu_Click);
-
if (!Directory.Exists(UserDirs[3, 1] + "\\" + parentmnu.Text + "\\Desktop"))
-
{
-
childDesktop.Enabled = false;
-
DisableAll = true;
-
}
-
-
childFavs.Text = "Favorites";
-
childFavs.Date = parentmnu.Text;
-
childFavs.Image = global::Backup.Properties.Resources.world;
-
childFavs.Click += new EventHandler(this.FavsMenu_Click);
-
if (!Directory.Exists(UserDirs[3, 1] + "\\" + parentmnu.Text + "\\Favorites"))
-
{
-
childFavs.Enabled = false;
-
DisableAll = true;
-
}
-
-
childMacros.Text = "Macros";
-
childMacros.Date = parentmnu.Text;
-
childMacros.Image = global::Backup.Properties.Resources.script_code;
-
childMacros.Click += new EventHandler(this.MacrosMenu_Click);
-
if (!Directory.Exists(UserDirs[3, 1] + "\\" + parentmnu.Text + "\\Macros"))
-
{
-
childMacros.Enabled = false;
-
DisableAll = true;
-
}
-
-
childAll.Text = "All";
-
childAll.Image = global::Backup.Properties.Resources.tick;
-
childAll.Click += new EventHandler(this.AllMenu_Click);
-
if (DisableAll) childAll.Enabled = false;
-
-
-
-
-
parentmnu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { childDesktop, childFavs, childMacros, childSeperator, childAll });
-
cmRestore.Items.AddRange(new ToolStripItem[] { parentmnu });
-
j++;
-
}
-
-
if (j == 0)
-
{
-
ToolStripMenuItem parentmnu = new ToolStripMenuItem();
-
parentmnu.Text = "No backups created";
-
parentmnu.Image = global::Backup.Properties.Resources.error;
-
cmRestore.Items.AddRange(new ToolStripItem[] { parentmnu });
-
}
-
}
-
-
catch (Exception ex)
-
{
-
ShowError("FATAL ERROR", ex.Message.ToString());
-
}
-
-
}
-
-
private void bwRestore_DoWork(object sender, DoWorkEventArgs e)
-
{
-
-
}
-
-
-
private void HDrive()
-
{
-
string HomeDirSpace = CalculateSize(new DirectoryInfo("H:\\")).ToString(); // Store Home drive space into a variable.
-
-
GetUnit(ref HomeDirSpace);
-
double percentage = (Convert.ToDouble(CalculateSize(new DirectoryInfo("H:\\"))) / 209715200) * 100;
-
-
//MessageBox.Show(percentage.ToString());
-
-
khpercentage.Values.Description = percentage.ToString("F0") + " %";
-
khpercentage.Width = Convert.ToInt32((percentage / 100) * 400);
-
lblSpace.Visible = false;
-
}
-
-
private void bwHdrive_DoWork(object sender, DoWorkEventArgs e)
-
{
-
string HomeDirSpace = CalculateSize(new DirectoryInfo("H:\\")).ToString(); // Store Home drive space into a variable.
-
lbHSpace.Text = "Home Drive Space";
-
GetUnit(ref HomeDirSpace);
-
double percentage = (Convert.ToDouble(CalculateSize(new DirectoryInfo("H:\\"))) / 209715200) * 100;
-
-
khpercentage.Values.Description = percentage.ToString("F0") + " %";
-
-
khpercentage.Width = ((int)percentage / 100) * 400;
-
-
lblSpace.Visible = false;
-
}
-
-
private void tmrFlash_Tick(object sender, EventArgs e)
-
{
-
int count = 0;
-
-
if (lblWarning.Visible)
-
{
-
lblWarning.Visible = false;
-
count++;
-
}
-
else if (count == 3)
-
{
-
lblWarning.Visible = true;
-
this.Enabled = false;
-
}
-
else
-
{
-
lblWarning.Visible = true;
-
}
-
}
-
-
/*-----------------------------------------------
-
* Event : ButtonDown
-
* Purpose : Trigger a mouse move event to move form around
-
* Args :
-
* sender (object)
-
* e (EventArgs)
-
* Returns : Null
-
* Author : Brendan Scarvell
-
* Date : 17 April 2008
-
* History :
-
* -----------------------------------------------
-
* 17/04/2008 Created
-
-----------------------------------------------*/
-
private void ButtonDown(object sender, MouseEventArgs mea)
-
{
-
diff_x = Form.MousePosition.X - Form.ActiveForm.Location.X;
-
diff_y = Form.MousePosition.Y - Form.ActiveForm.Location.Y;
-
this.hdrTitleBar.MouseMove += new MouseEventHandler(Form_MouseMove);
-
}
-
-
/*-----------------------------------------------
-
* Event : ButtonDown
-
* Purpose : Trigger a mouse move event to move form around
-
* Args :
-
* sender (object)
-
* e (EventArgs)
-
* Returns : Null
-
* Author : Brendan Scarvell
-
* Date : 17 April 2008
-
* History :
-
* -----------------------------------------------
-
* 17/04/2008 Created
-
-----------------------------------------------*/
-
private void Form_MouseMove(object sender, MouseEventArgs e)
-
{
-
//as the mouse point moves the form moves with it
-
Point p = new Point(MousePosition.X - diff_x, MousePosition.Y - diff_y);
-
Form.ActiveForm.Location = p;
-
//creates the MouseUp eventhandler
-
this.hdrTitleBar.MouseUp += new System.Windows.Forms.MouseEventHandler(Form_MouseUp);
-
}
-
-
/*-----------------------------------------------
-
* Event : ButtonDown
-
* Purpose : Trigger a mouse move event to move form around
-
* Args :
-
* sender (object)
-
* e (EventArgs)
-
* Returns : Null
-
* Author : Brendan Scarvell
-
* Date : 17 April 2008
-
* History :
-
* -----------------------------------------------
-
* 17/04/2008 Created
-
-----------------------------------------------*/
-
private void Form_MouseUp(object sender, MouseEventArgs e)
-
{
-
//on MouseUp event, remove the MouseMove eventhandler
-
this.hdrTitleBar.MouseMove -= new MouseEventHandler(Form_MouseMove);
-
}
-
-
// Error procedure
-
-
private void ShowError(string title, string body)
-
{
-
// Move the form size to display error box
-
frmMain.ActiveForm.Size = new System.Drawing.Size(frmMain.ActiveForm.Size.Width, frmMain.ActiveForm.Size.Height + 80);
-
pnlMenu.Location = new System.Drawing.Point(11, (pnlMenu.Location.Y + 80));
-
pnlSpace.Location = new System.Drawing.Point(pnlSpace.Location.X, (pnlSpace.Location.Y + 80));
-
//pnlFiles.Location = new System.Drawing.Point(pnlFiles.Location.X, (pnlFiles.Location.Y + 80));
-
cmdQuit.Location = new System.Drawing.Point(cmdQuit.Location.X, (cmdQuit.Location.Y + 80));
-
-
kpError.Visible = true;
-
lblWarning.Text = title;
-
lblMessage.Text = body;
-
}
-
-
private void ClearError()
-
{
-
frmMain.ActiveForm.Size = new System.Drawing.Size(frmMain.ActiveForm.Size.Width, frmMain.ActiveForm.Size.Height - 80);
-
pnlMenu.Location = new System.Drawing.Point(11, (pnlMenu.Location.Y - 80));
-
pnlSpace.Location = new System.Drawing.Point(pnlSpace.Location.X, (pnlSpace.Location.Y - 80));
-
//pnlFiles.Location = new System.Drawing.Point(pnlFiles.Location.X, (pnlFiles.Location.Y - 80));
-
cmdQuit.Location = new System.Drawing.Point(cmdQuit.Location.X, (cmdQuit.Location.Y - 80));
-
-
-
kpError.Visible = false; ;
-
lblWarning.Text = "";
-
lblMessage.Text = "";
-
}
-
-
private void kryptonButton2_Click_1(object sender, EventArgs e)
-
{
-
ClearError();
-
}
-
-
private void cmdBackup_Click(object sender, EventArgs e)
-
{
-
DialogResult a = MessageBox.Show("Are you sure you wish to back your Desktop, Favourites and Macros?", "Back Up", MessageBoxButtons.YesNo);
-
-
if (a == DialogResult.Yes)
-
{
-
MessageBox.Show("Perform backup");
-
}
-
-
else
-
{
-
MessageBox.Show("Abort");
-
}
-
-
}
-
-
private void asdf_Click(object sender, EventArgs e)
-
{
-
MessageBox.Show("Testorama");
-
-
}
-
-
private void cmdRefresh_Click_1(object sender, EventArgs e)
-
{
-
-
lblSpace.Visible = true;
-
Thread t = new Thread(HDrive);
-
t.Start();
-
}
-
-
private void kcmBackup_Opening(object sender, CancelEventArgs e)
-
{
-
-
}
-
-
private void BackupDesktop_Click(object sender, EventArgs e)
-
{
-
DialogResult dr;
-
bool msgbox;
-
dr = MessageBox.Show("Are you sure you wish to backup your desktop icons?", "Desktop Backup", MessageBoxButtons.YesNo);
-
-
if (dr == DialogResult.Yes)
-
{
-
msgbox = CopyRecursiveFiles(new DirectoryInfo(UserDirs[1, 1]), UserDirs[3,1] + DATE + "\\" + UserDirs[1,0], false, "*");
-
if (msgbox) MessageBox.Show("Desktop Backup Completed Successfully");
-
}
-
-
}
-
-
private void BackupFavs_Click(object sender, EventArgs e)
-
{
-
DialogResult dr;
-
bool msgbox;
-
-
dr = MessageBox.Show("Are you sure you wish to backup your favorites?", "Desktop Backup", MessageBoxButtons.YesNo);
-
-
if (dr == DialogResult.Yes)
-
{
-
msgbox = CopyRecursiveFiles(new DirectoryInfo(UserDirs[0, 1]), UserDirs[3, 1] + DATE + "\\" + UserDirs[0, 0], false, "*");
-
if (msgbox) MessageBox.Show("Favorites Backup Completed Successfully");
-
}
-
}
-
-
private void BackupMacros_Click(object sender, EventArgs e)
-
{
-
DialogResult dr;
-
bool msgbox;
-
-
dr = MessageBox.Show("Are you sure you wish to backup your macros?", "Desktop Backup", MessageBoxButtons.YesNo);
-
-
if (dr == DialogResult.Yes)
-
{
-
msgbox = CopyRecursiveFiles(new DirectoryInfo(UserDirs[2, 1]), UserDirs[3, 1] + DATE + "\\" + UserDirs[2, 0], false, "*");
-
-
if (msgbox) MessageBox.Show("Macros Backup Completed Successfully");
-
}
-
-
}
-
-
private void BackupAll_Click(object sender, EventArgs e)
-
{
-
-
DialogResult dr;
-
bool msgbox,msgbox2,msgbox3;
-
-
dr = MessageBox.Show("Are you sure you wish to perform a full backup? \n\n WARNING: This could be a time consuming process", "Backup", MessageBoxButtons.YesNo);
-
-
if (dr == DialogResult.Yes)
-
{
-
msgbox = CopyRecursiveFiles(new DirectoryInfo(UserDirs[0, 1]), UserDirs[3, 1] + DATE + "\\" + UserDirs[0, 0], false, "*");
-
msgbox2 = CopyRecursiveFiles(new DirectoryInfo(UserDirs[1, 1]), UserDirs[3, 1] + DATE + "\\" + UserDirs[1, 0], false, "*");
-
msgbox3 = CopyRecursiveFiles(new DirectoryInfo(UserDirs[2, 1]), UserDirs[3, 1] + DATE + "\\" + UserDirs[2, 0], false, "*");
-
-
if (msgbox && msgbox2 && msgbox3) MessageBox.Show("Backup Completed Successfully");
-
}
-
}
-
-
private void tmrRestore_Tick(object sender, EventArgs e)
-
{
-
Thread r = new Thread(Restore);
-
r.Start();
-
}
-
-
}
-
-
}
-
Any help would be greatly,greatly,greatly appreciated
| |
Share:
Expert 4TB |
Somewhere you are using an object that has not been defined (it is still null)
Try running in debug to get a better idea of where it is erroring.
since there was no line number listed in the stack trace I am guessing it is happening in the constructor.
Either yours or the ComponentFactory.Krypton.Toolkit.KryptonForm class's constructor.
Although if your timer_tick function executes before this line:
InitializeComponent();
it might cause trouble too
| | Expert 2GB | - System.NullReferenceException: Object reference not set to an instance of an object.
-
at Backup.frmMain.ShowError(String title, String body)
-
at Backup.frmMain.Form1_Load(Object sender, EventArgs e)
-
at System.Windows.Forms.Form.OnLoad(EventArgs e)
-
at ComponentFactory.Krypton.Toolkit.KryptonForm.OnLoad(EventArgs e)
-
at System.Windows.Forms.Form.OnCreateControl()
-
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
-
at System.Windows.Forms.Control.CreateControl()
-
A tip on reading these. They are in reverse chronological order. Meaning the line at the bottom happened first, the line at the top was most recent and right before the crash.
So you got as far as Backup.frmMain.Form1_Load, then crashed at .ShowError(string title, string body);
I'd start with putting a breakpoint at the first line of your ShowError method and walk through checking to see which variables are null.
| | Expert 2GB |
You might also find that a Dictionary<string, string> to be more friendly than a String[ , ]
| | |
Thanks for the help, It definitely is that ShowError procedure, so I have to work out why its doing it (errors on the H drive check). If i log into the network and I have a home drive, (ie: doesnt call the ShowError message), I receive the following.
See Image: http://img21.imageshack.us/img21/6205/errorg.png
What would be causing that? This is only re-producable on the test box. The Development box doesnt do this, so im assuming something is installed, or something's on here that's not on that.
| | |
Also, not sure if this is any other help:
Filename: ContextMenu.cs
============================= -
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.Windows.Forms;
-
using System.IO;
-
using System.Threading;
-
using ComponentFactory.Krypton.Toolkit;
-
-
namespace Backup
-
{
-
class ContextMenu : ToolStripMenuItem
-
{
-
public string m_date;
-
-
public ContextMenu()
-
{
-
-
}
-
-
public string Date
-
{
-
get
-
{
-
return m_date;
-
}
-
-
set
-
{
-
m_date = value;
-
}
-
}
-
-
}
-
}
-
-
| | Expert 2GB | @xenoix
Notice how lines 265 and 459 aren't exactly formated the same.
| | |
Thanks alot for that, that has resolved the null problem.
Any tips for that other pesky error? As soon as the application executes, I get that "Backup has encountered a problem and needs to close." I have some feeling that something isnt installed on the other PC because this doesnt happen on my development PC. They both have .NET Framework 2 installed.
| | Expert 2GB |
Breakpoints are your friend. Put one early and follow it step-by-step with F-10
Logging... Say it with me... Logging. Have every method write to a text file at the start and end. You can trace how far it got.
Mine tend to start out with environmental information so I can get a feel for the client machine - 31Mar09 16:11:03.562 #######################################################################
-
31Mar09 16:11:03.578 Starting 'MyGreatApplication', version 1.0.0.0 (1.0.0.0)
-
31Mar09 16:11:03.578 Saint '1.0.0.5'
-
31Mar09 16:11:03.578 System Drive: 'C:'
-
31Mar09 16:11:03.578 Logged on as: 'Clint'
-
31Mar09 16:11:03.609 Domain : '''
-
31Mar09 16:11:03.718 Workgroup : 'HomeOffice''
-
31Mar09 16:11:03.734 Processor(s): 2 x x86 Family 15 Model 107 Stepping 1, AuthenticAMD
-
31Mar09 16:11:03.734 Physical Memory: 3071 MB
-
31Mar09 16:11:03.734 Free memory : 1287 MB
-
31Mar09 16:11:03.734 Free VM : 1829 MB
-
31Mar09 16:11:03.828 Op. Sys. : Microsoft Windows XP Professional (Win32NT)
-
31Mar09 16:11:03.828 Op. Sys. : Microsoft Windows NT 5.1.2600 Service Pack 3'
-
31Mar09 16:11:03.828 ===============Network Drives====================
-
31Mar09 16:11:03.843 =============== Local Drives=====================
-
31Mar09 16:11:03.843 Drive: A:\ (Removable)
-
31Mar09 16:11:04.062 Drive: C:\ (Fixed) 118.74 gig free of 232.88 gig total. SN: 9093FDAE
-
31Mar09 16:11:04.093 Drive: D:\ (Fixed) 294.84 gig free of 931.51 gig total. SN: CC199307
-
31Mar09 16:11:04.093 Drive: E:\ (Removable)
-
31Mar09 16:11:04.093 Drive: F:\ (Removable)
-
31Mar09 16:11:04.093 Drive: G:\ (Removable)
-
31Mar09 16:11:04.125 Drive: H:\ (Fixed) 229.47 gig free of 298.02 gig total. SN: 3BEC9DA3
-
31Mar09 16:11:04.125 Drive: I:\ (CDRom)
-
31Mar09 16:11:04.125 Drive: J:\ (Removable)
-
31Mar09 16:11:04.125 Drive: L:\ (CDRom)
-
31Mar09 16:11:04.140 Drive: P:\ (Fixed) 138.41 gig free of 232.88 gig total. SN: 9093FDAE
-
31Mar09 16:11:04.171 Drive: Q:\ (Fixed) 155.30 gig free of 232.88 gig total. SN: 9093FDAE
-
31Mar09 16:11:04.187 Drive: R:\ (Fixed) 146.47 gig free of 232.88 gig total. SN: 9093FDAE
-
31Mar09 16:11:04.203 Drive: S:\ (Fixed) 127.42 gig free of 232.88 gig total. SN: 9093FDAE
-
31Mar09 16:11:04.203 ===============Display adapters===============
-
31Mar09 16:11:04.218 0, DISPLAY1, ATI FireMV 2400, 134217733, PCI\VEN_1002&DEV_3151&SUBSYS_31511002&REV_00, \Registry\Machine\System\CurrentControlSet\Control\Video\{E6130F33-B2F7-43F6-9548-7629A84587B2}\0000
-
31Mar09 16:11:04.234 1, DISPLAY2, ATI FireMV 2400 Secondary, 134217729, PCI\VEN_1002&DEV_3171&SUBSYS_31501002&REV_00, \Registry\Machine\System\CurrentControlSet\Control\Video\{32124523-E7FE-4C57-A14A-8FF4D0D372A9}\0000
-
31Mar09 16:11:04.234 2, DISPLAY3, ATI FireMV 2400, 1, PCI\VEN_1002&DEV_3151&SUBSYS_31511002&REV_00, \Registry\Machine\System\CurrentControlSet\Control\Video\{BED9F312-5DA2-4DA7-AE5C-1459C5170984}\0000
-
31Mar09 16:11:04.265 3, DISPLAY4, ATI FireMV 2400 Secondary, 1, PCI\VEN_1002&DEV_3171&SUBSYS_31501002&REV_00, \Registry\Machine\System\CurrentControlSet\Control\Video\{E9C45A42-A6F7-49D2-A2E9-BAD379636B3A}\0000
-
31Mar09 16:11:04.359 4, DISPLAYV1, NetMeeting driver, 8, , \Registry\Machine\System\CurrentControlSet\Control\Video\{8B6D7859-A639-4A15-8790-7161976D057A}\0000
-
31Mar09 16:11:04.359 5, DISPLAYV2, RDPDD Chained DD, 8, , \Registry\Machine\System\CurrentControlSet\Control\Video\{DEB039CC-B704-4F53-B43E-9DD4432FA2E9}\0000
-
31Mar09 16:11:04.359 ===================Displays=====================
-
31Mar09 16:11:04.359 Array 0: 'DISPLAY1', {X=0,Y=0,Width=1920,Height=1136}
-
31Mar09 16:11:04.359 Array 1: 'DISPLAY2', {X=4170,Y=680,Width=1024,Height=768}
-
31Mar09 16:11:04.359 Array 2: 'DISPLAY3', {X=3120,Y=-480,Width=1050,Height=1680}
-
31Mar09 16:11:04.359 Array 3: 'DISPLAY4', {X=1920,Y=-720,Width=1200,Height=1920}
-
31Mar09 16:11:04.359 ===================Serial Ports=====================
-
31Mar09 16:11:04.359 COM3
-
31Mar09 16:11:04.359 COM4
-
31Mar09 16:11:04.375 #######################################################################
| | Expert 2GB |
OH - And I highly recommend putting in some type of Virtual Machine system on your development PC. Its really nice to test on WinXPsp1, WinXPsp2, WinVista... etc. without having to have multiple computers.
Another test for you could be sheer number of files being backed up. Your development machine works fine backing up 50, but what happens for the user when it goes to back up 5,000? Too many threads... in sufficient memory...
Or user rights... Your development machine has god priviledges to the server but your users don't...
| | |
That logging stuff you posted up there, you wouldn't happen to be able to share that at all? =P
(the code for that, that is) I love the Removable drive part.. Something im looking for another application im wanting to write.
| | Expert 2GB | @xenoix
I preach way too much to the effect of:
Can anybody send me code to [...]
The Bytes volunteers are not here to write your code for you.
Bytes is very much a "Give me a fish I eat for a day. Teach me to fish I eat for a lifetime" kind of place. Just giving you the code doesn't help you learn near as effectively as good old-fashioned trial and error.
So I will follow my own advice by pointing you at where to read up. System.IO.DriveInfo.GetDrives(); | | Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
18 posts
views
Thread by Ken |
last post: by
|
5 posts
views
Thread by Carmine Cairo |
last post: by
|
4 posts
views
Thread by Christaaay |
last post: by
|
1 post
views
Thread by MLH |
last post: by
|
1 post
views
Thread by Mark |
last post: by
|
1 post
views
Thread by Alfonso Morra |
last post: by
|
4 posts
views
Thread by HNguyen |
last post: by
|
15 posts
views
Thread by Khurram |
last post: by
|
9 posts
views
Thread by ThunderMusic |
last post: by
| | | | | | | | | | | |