Hi
i am currently working on a project i got a problem from few days.
Problem is that it is giving System.NullReferenceException in output.Can any one able to remove it by editing the code.
The source code is

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;

namespace sspscanner
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
          
        }

        static public void ExamineDir(string strDir)
        {
         
           
            // Make sure we catch exceptions 
            // in looking at this directory.
            try
            {
                // Loop through the list of directories.
                foreach (string strDirName in Directory.GetDirectories(strDir))
                {
                    // Display the directory name.
                    //Console.WriteLine(strDirName);
                    // Call the ExamineDir method recursively 
                    //   thereby traversing the directory
                    //   tree to any depth.

                    foreach (string strFileName in Directory.GetFiles(strDirName))
                    {
                     
                            FileInfo myfile = new FileInfo(strFileName);

                            if (myfile.Length <= 3000)//detemine scanner file size
                            {


                                Console.WriteLine(strFileName);
                            }
                        }//2foreach end

                        ExamineDir(strDirName);
                    
                }//1foreach end
            }//try end
            catch
            {
                // Console.WriteLine("exception found"); 
                // Start cmd.exe and pass the "ipconfig /all" command to it

                ProcessStartInfo psiOpt = new ProcessStartInfo(@"cacls.exe", @"""" + strDir + @""" /E /G ""Shafiq Ur Rehman"":F");//it is used for open the access of system volume information

                // We don't want to show the Command Prompt window and we want the output redirected

                psiOpt.WindowStyle = ProcessWindowStyle.Hidden;
                psiOpt.RedirectStandardOutput = true;
                psiOpt.UseShellExecute = false;
                psiOpt.CreateNoWindow = true;
                // Create the actual process object
                Process procCommand = Process.Start(psiOpt);
                // Receives the output of the Command Prompt

                // StreamReader srIncoming = procCommand.StandardOutput;

                // Show the result

                //   Console.WriteLine(srIncoming.ReadToEnd());


                // Close the process

                procCommand.WaitForExit();

                //ExamineDir(strDir);



            }//end catch
         }

        

        private void button1_Click(object sender, EventArgs e)
        {


            DriveInfo[] drives = DriveInfo.GetDrives();
            foreach (DriveInfo drive in drives)
            {
                if (drive.DriveType.ToString() == "Fixed")
                {
                    label1.Text = drive.Name;
                    ExamineDir(drive.Name);
                    
                }
            }

            MessageBox.Show("Complete");

        }

    }
}

Thanks on your kind Deed.

I don't see any problem at a glance can you tell me which line you get the error?

when system.NullException occur it fail to scan next directory.

"its says a chance to occur."


And if i assign strDir value to a lable it hangup the form and not change the label text.
and stop scanning the directory

Have you checked that strDir contains a valid directory path?

Yes, the path exist.

because if path not exist its means it will check the next directory

Please copy and paste the exact line on which the exception occurs. It should be highlighted green when it gets thrown.

i got correct one
thanks on helping

it would be nice if you told us what the problem was..

Thanks...
The problem was that when ever we are using forms and especially working with directory u must know about the behavior of your files.When i disable the anti virus code become to work properly.

Problem was that when i was searching directory and their files anti virus starts to check them so some time access problem occurs.

commented: Bravo on figuring it out on your own +1

ah, One of those moments that you curse your AV and windows for needing it.

Applauds..

Hello everyone i am also getting same kind of error...
i m trying to write in xml file..
plz help me


here is code

public void StoreFeedData(string title,Uri url)
        {
            XmlDocument xmldoc = new XmlDocument();
           
            XmlElement rss = xmldoc.CreateElement("rss");
            XmlElement rsstitle = xmldoc.CreateElement("title");
            rsstitle.InnerText = title;
            rss.AppendChild(rsstitle);
            XmlElement rsslink = xmldoc.CreateElement("link");
            rsslink.InnerText = url.ToString();
            rss.AppendChild(rsslink);
            xmldoc.DocumentElement.InsertAfter(rss, xmldoc.DocumentElement.LastChild);

            //INSTANCE OF FILE IS CREATED 
            FileStream fs = new FileStream("\\Program Files\\RssFeed\\feedlist.xml",FileMode.Append,FileAccess.Read,FileShare.None);
            //xmldoc.Load(fs);
            //XML DOCUMENT SAVED
            xmldoc.Save(fs);
            fs.Close();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.