You must Sign In to post a response.
  • Category: .NET

    Network path not found

    Hi,

    I am trying to check weather network path exist or not .

    i have some directory structure on network and i am check weather folder exist or not

    i am using directory info class using .exist method ,its working fine .

    but sometime when network path is not accessible is gives exception "network path not found "

    How to resolve or check for this problem ? Any code please provide !! Help !!!
  • #764479
    How you can resolve this ? obviously when you are trying to access network path and if the network has not authenticated, then it will ask you for network credential and you need to enter uid and password for it. so at this time we got network path not exist issue.
    So, finally we can say that we got same exception even path is not exist or network path is not authenticated.

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764486
    Hi,
    As Mr. Prasad Kulkarni sir said, we have to check accessing that network folder through command prompt. If it asks for uid and pwd then we must have to specify it.
    Though you can handle this situation using this code:
    DirectoryInfo drInfo = null;
    try
    {
    drInfo = new DirectoryInfo(@"D:\Xamarin");
    if (drInfo.Exists)
    {
    Console.WriteLine("Folder exist.!");
    }
    else
    {
    Console.WriteLine("Folder not exist.!");
    }
    }
    catch (Exception ex)
    {
    if (ex.Message.Trim().ToLower().Contains("network path not found"))
    Console.WriteLine("Error: You don't have acces to network path '" + drInfo.FullName + "'. Please provide valid credentials!");
    else
    Console.WriteLine("Error: " + ex.Message);
    }
    Hope it helps.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com

  • #764487
    Thanks for Replying ,

    I am stuck with two type of exception

    1) network path not found (some time occur , needs to handle)

    2) network folder is not accessible (most of the time occur , need to be handle )

    I have the authentication for the network path .

    Actually when i am trying to access the network path by using directory info class Exists method [ if(di.exists) {} ]. if network path is ok di.exists given me true and i collect the result , if false i show a message that this directory does not exists.

    but some times if network path is not accessible it given exception on line di.GetDirectories()

    if(di.exists).
    {
    dirarr[]=di.GetDirectories() ;
    int count=dirarr.count();
    }
    count of folder i am collecting in datatable and passing it to method ,that method will trigger a mail showing count of folder , if folder doesnot exist if will show " this folder does not exists". i cannot use result in exception as you have suggested as i need to send the result collected in datatable to a method as explain above
    ideally i want that if at any moment network path is not accessible or network path not found it should handled and shown in at what specific folder this exception has occurred so that i can handle and shown in message ,so that user could be able to see at which folder is not accessible .

  • #764489
    Hi,
    As I had given in code snippet: you have to declare DirectoryInfo object outside try or as global variable and when the exception is caught i.e. in catch(), you have to just write "DirectoryInfoObject.FullName" in message which will give you the full name/full directory path with respect to the specific folder.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com

  • #764501
    Hi Shashikant,
    Is there any way to check this in if condition rather then in exception

  • #764502
    yes you can handle it while di.GetDirectories(). Follow this:
    if(di.exists).
    {
    try
    {
    dirarr[]=di.GetDirectories() ;
    int count=dirarr.count();
    }
    catch(Exception eInner)
    {
    Console.WriteLine("Error: You don't have acces to network path '" + di.FullName + "'. Please provide valid credentials!");
    }
    }//... End if

  • #764503
    Hi Shahikant ,

    my if condition is in for loop ,so once exception occur there will be no point on where again the execution of loop start again .

    That why i asked you for checking in if condition rather then in exception

  • #764988
    dts.Columns.Add("Srno"); //
    dts.Columns.Add("Directory"); //--------------------------------------- CREATING COLUMN'S FOR DATATABLE.
    dts.Columns.Add("count"); //
    if (dt.Rows.Count > 0)
    {
    foreach (DataRow subDir in dt.Rows)
    {
    Srno = Srno + 1;
    if (subDir["MT"] != null)
    {
    Subroot = root + subDir["MT"].ToString() + "\\" + "Project"; //---------- CREATING NEW ROOT LOCATION PROJECT .
    di = new DirectoryInfo(Subroot);
    if (di.Parent.Exists)
    {
    if (di.Exists)
    {
    diArrProj = di.GetDirectories();
    count = diArrProj.Count();
    dts.Rows.Add(Srno, subDir["MT"].ToString(), count);
    Subroot = string.Empty;
    count = 0;
    }
    else
    {
    dts.Rows.Add(Srno, "<font color='red'>" + subDir["PDMT"].ToString() + "</font>", Message);
    Subroot = string.Empty;
    count = 0;
    }
    }
    else
    {
    dts.Rows.Add(Srno, "<font color='red'>" + subDir["MT"].ToString() + "</font>", Message);
    Subroot = string.Empty;
    count = 0;
    }
    }
    else
    {
    dts.Rows.Add(Srno, "<font color='red'>" + subDir["MT"].ToString() + "</font>", Message);
    Subroot = string.Empty;
    count = 0;
    }
    }
    if (dts.Rows.Count > 0)
    {
    string htmlString = getHtmlMailBody(dts);

    SendAutomatedEmail(htmlString, addresses);
    }
    }
    }
    }
    catch (Exception ex)
    {
    SendAutomatedEmail(ex.ToString(), "");
    }


    As you can see at dirArr=di.getdirectories();
    if network path is not accessible at di.getdirectoires() i am getting exception.

    i dont want to handle this in exception in catch

    just in if condition through loop i want to some that if network path is not accessible for particular folder it will go in else condition and then i will display msg that this folder is not accesible .

    i dont have to check for one folder in network there could be 10 folder or more than that , thus i have to loop through each and every folder check weather di.getdirectories() gives me directories so i pull count of it which are inside main folder . but if one folder is not accessible then i get a exception at di.getdirectories(), so ideally it di.exist should check this but its getting bypass some how dont have clue for it .

    Please Help i am badly stuck in this


Sign In to post your comments