CFanatic

Go Back   CFanatic > Programming > C# Programming

Join CFanatic Forum Now

Object not set to an Instance of an Object topic posted under C# Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 09-07-2010, 09:20 AM
Junior Member
 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
dumbestcrayon is on a distinguished road
| More
Object not set to an Instance of an Object

Okay, My program gathers the drive information of the mounted drives and sets one of them as the location to save their information. For some reason I'm not getting any error while debugging but almost everybody gets an error when I publish the program. Here is the error I get followed by the lines of code where the error occurs. I am not seeing where I haven't set an Object as an instance. Many thanks in advance for the help..


:::Error:::
Code:
Method: Void setPersonalDrive()
Object reference not set to an instance of an object.
   at U_Notes_V3.MainWindow.setPersonalDrive()
   at U_Notes_V3.MainWindow.Form1_Load(Object sender, EventArgs e)
   at System.Windows.Forms.Form.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 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)
:::Code:::
Code:
private void setPersonalDrive()
        {
            DriveInfo[] drives = DriveInfo.GetDrives();
            DriveInfo storeDrive = new DriveInfo("C");

            try
            {
                storeDrive = getPersonalDriveInfo(drives);
            }
            catch
            {
                storeDrive = getLsDriveInfo(drives);
            }
            

            Settings.Default.logStoreLocation = storeDrive.RootDirectory.ToString();

            if (storeDrive.TotalSize != 4294967296)
            {
                Settings.Default.logStoreLocation = storeDrive.RootDirectory.ToString() 
                    + SystemInformation.UserName.ToLower().Trim() + "\\";

                if (!Directory.Exists(Settings.Default.logStoreLocation))
                {
                    try
                    {
                        Directory.CreateDirectory(Settings.Default.logStoreLocation);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("U-notes was unable to create your log directory.\n" +
                            "Please contact bj2356 immediately with this information");

                    }

                }
            }
            else if (storeDrive.TotalSize == 4294967296)
            {
                Settings.Default.logStoreLocation = storeDrive.RootDirectory.ToString();
            }
            
        }

        private DriveInfo getPersonalDriveInfo(DriveInfo[] drives)
        {
            for (int i = 0; i < drives.Length; i++)
            {
                if (drives[i].IsReady)
                {
                    if (drives[i].TotalSize == 4294967296)
                    {
                        return drives[i];
                        
                    }
                }
            }
            return null;
        }

        private DriveInfo getLsDriveInfo(DriveInfo[] drives)
        {
            for (int i = 0; i < drives.Length; i++)
            {
                if (drives[i].IsReady)
                {
                    if (drives[i].VolumeLabel.ToLower().Contains("txdlls2cdfile02"))
                    {
                        return drives[i];

                    }
                }
            }
            return null;
        }
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Loading XML Object from a string amer.m C# Programming 0 08-28-2010 03:11 AM
COM Object C++ and VBA nsujan Win32 Programming 0 08-28-2010 03:00 AM
Creating Function Object santoshmca.giit C++ Programming 0 07-19-2010 07:14 AM
Component Object Model imaginative.bibhas C++ Programming 1 09-19-2008 11:23 AM
shared object in GAC across processes AmilHanish C# Programming 0 09-29-2006 06:49 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 03:45 PM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board