Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, March 19, 2013 6:29 PM
Dear All,
i want to validate if a remote shared path exist.
Is there any way to do this, i used code below but its showing error.
string remoteDirectoryPath = @"\\192.168.98.15\abc\Test";
if (!Directory.Exists(remoteDirectoryPath))
{
MessageBox.Show(string.Format("Unable to Access Path= {0}", remoteDirectoryPath), "Path Access Failure", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Directory.exist(remoteDirectoryPath) is not able to validate directory exist or not.
\192.168.98.15\abc\Test is accesible through run
All replies (5)
Thursday, March 21, 2013 9:03 AM âś…Answered
Hi Harish,
Welcome to MSDN Forum Support.
You can use following code that check the any file exist of not, in case of file not exist it return the 404 error, file not exist.
WebRequest request;
WebResponse response;
String strMSG = string.Empty;
request = WebRequest.Create(new Uri(NetWorkPath));
request.Method = "HEAD";
try
{
response = request.GetResponse();
strMSG = string.Format("{0} {1}", response.ContentLength, response.ContentType);
}
catch (Exception ex)
{
//In case of File not Exist Server return the (404) Error
}
For its detailed explanations, you can refer to this forum thread named How to validating the existence of a remote directory.
Sincerely,
Jason Wang
Jason Wang [MSFT]
MSDN Community Support | Feedback to us
Tuesday, March 19, 2013 6:35 PM
Hi,
Please always post the exact error message. It seems to work fine here...
Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
Tuesday, March 19, 2013 6:39 PM
Dear Patrice Scribe,
Thanks for the advice.
It's not showing any error or exception,
if (!Directory.Exists(remoteDirectoryPath))
it is showing directory not exist, but it is accessible through run command
Tuesday, March 19, 2013 7:15 PM
Is Test a directory? Directory.Exists fails on files. Exists doesn't raise exceptions on errors. It just returns false if the path doesn't result in a Directory that has read access (at least).
Wednesday, March 20, 2013 10:30 AM
What if you place a simple txt file in this directory and use File.ReadAllText to read it ? This is just to see if you could have some exception that will better help in understanding what happens.
I gave this a try (with an IP address) and it seems to work fine. So I can only assume some particular condition on your side (when using "run" you are really using the same account than your app ?)
Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".