Click here to Skip to main content
15,917,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need to specify the path of my local system and one server in a console application.And i specified it like shown below.
var savePath = "\\\\149.223.26.33\\D:\\Developers\\muralim\\TRW.HRM.Headcount_LMSFeed\\Log\\empps.txt";


            var filePath = "C:\\Documents and Settings\\aj99823\\Desktop\\project\\employeedetails1.txt";


but the program is throwing error saying the path's format spcified is not correct.can anyone plss help me...???
Posted
Updated 24-May-12 1:12am
v3
Comments
hitech_s 24-May-12 6:28am    
at savepath you are getting error i think?
amaljosep 24-May-12 6:35am    
yes..i also think so..

If you tried to do this in explorer, you'd get an error. The reason is, to refer to the drive on another machine, you'd have to you the $ sign, like this:
C#
var savePath = "\\\\149.223.26.33\\D$\\Developers\\muralim\\TRW.HRM.Headcount_LMSFeed\\Log\\empps.txt";
[Edit]Like an idiot, I forgot to remove the :. Sorted now.
 
Share this answer
 
v2
Comments
amaljosep 24-May-12 6:34am    
thanks a lot for helping me....but still its giving me the same error.
Pete O'Hanlon 24-May-12 6:45am    
That was because I meant to overwrite the : with the $ but I didn't. Take a look at the update to the solution. BTW - this will only work if you have permissons to access that drive using the $ syntax.
amaljosep 24-May-12 8:29am    
still its giving me error saying "network path cannot be found"..wat can be the reasons??
Pete O'Hanlon 24-May-12 8:41am    
As I said, you have permission problems. Take a look here to get a better understanding of what you need to do to fix it: http://stackoverflow.com/questions/295538/how-to-provide-user-name-and-password-when-connecting-to-a-network-share
amaljosep 24-May-12 8:54am    
i am using the corresponding code from the page you specified,

public void OpenNetworkConnection(string savePath, string username, string password)
{
var directory = Path.GetDirectoryName(savePath).Trim();
var process = new Process { StartInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Hidden, FileName = "cmd.exe", Arguments = "NET USE " + directory + " /user:" + username + " " + password
}
};
process.Start();
process.Close(); }

public void CloseNetworkConnection(string savePath)
{
var directory = Path.GetDirectoryName(savePath).Trim();
var process = new Process
{
StartInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Hidden, FileName = "cmd.exe", Arguments = "NET USE " + directory + " /delete"
}
};
process.Start();
process.Close(); }

}
Have you tried @ operator infront of the string..

C#
 var savePath = @"\\149.223.26.33\D$\Developers\muralim\TRW.HRM.Headcount_LMSFeed\Log\empps.txt";
                
var filePath = @"C:\Documents and Settings\aj99823\Desktop\project\employeedetails1.txt";
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900