2

I can see a network share in explorer but when I use try to access it in my application I get "The network name cannot be found."

This is quite odd because the same server has other shares that I can access. For example:

string[] example_directories = new string[]{        
    Path.Combine(@"\\example01","vaqua"),
    Path.Combine(@"\\example01","vaqua-pub"),
    Path.Combine(@"\\example01","yesvirginiabeach"),
    Path.Combine(@"\\example01","yesvirginiabeach-pub")
};

// output username
Console.WriteLine("User: " + WindowsIdentity.GetCurrent().Name);

// output each response to Directory.Exists 
foreach (string directory in example_directories)
    try
    {
        Console.WriteLine(directory + " : " + Directory.GetCreationTime(directory));
    }
    catch(Exception e)
    {
        Console.WriteLine(directory + " : " + e.Message.Trim());
    }

Console.Read();

Output:

User: domain\myusername
\\example01\vaqua : 10/22/2013 7:34:30 AM
\\example01\vaqua-pub : 10/22/2013 7:57:42 AM
\\example01\yesvirginiabeach : The network name cannot be found.
\\example01\yesvirginiabeach-pub : 4/4/2013 10:31:07 AM

I can see all four of those shares on \example01 in explorer but the \example01\yesvirginiabeach share just doesn't exist to my application.

These four shares all have the same permissions and I even print out my username to ensure the app is running with my creds.

I have had our admin re-share the directory and re-apply permissions to no avail.

Solution: My admin misspelled the share name:

\\example01\yesvirginiabeach as \\example01\yesvirgniabeach.

iambriansreed
  • 21,935
  • 6
  • 63
  • 79
  • 1
    Have a look at this post: http://stackoverflow.com/questions/17472168/check-if-directory-exists-on-network-drive – Mike Perrenoud Dec 19 '13 at 21:30
  • 1
    Have you double-checked that the name `"yesvirginiabeach"` is correct? Make sure there's nothing crazy like a Unicode character that looks like an `"i"` but is really a different character. – TypeIA Dec 19 '13 at 21:31
  • 1
    Also maybe try [enumerating the shares](http://stackoverflow.com/questions/2091126/enumerating-network-shares-with-c-sharp) (see link for code) and see what your program can see. – TypeIA Dec 19 '13 at 21:32
  • @DavidNorris Please combine your comments into an answer. The folder name upon closer inspection was yesvirgniabeach. Ugh. Admins. I found this out by enumerating the shares. Thanks dude! – iambriansreed Dec 19 '13 at 21:49

1 Answers1

1

(Answered and resolved in comments above...)

Double-check that the name "yesvirginiabeach" is correct. Make sure there's nothing crazy like a Unicode character that looks like an "i" but is really a different character. (Solution turned out to be that someone misspelled the name of the folder as "yesvirgniabeach".)

For similar problems one could try enumerating the shares to see what the program can see. There's also the NET USE command (open a Command Prompt and type net use /help; this tool shows all the shares currently being accessed and can open new shares from a command prompt, which sometimes gives useful status messages).

Community
  • 1
  • 1
TypeIA
  • 16,916
  • 1
  • 38
  • 52