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, January 29, 2013 1:32 PM
I have a question about 2 C# 2010 windows applications that I am running:
In one program I am <appSettings>
< add key="FileLocation" value="D:App\Staging" />
< /appSettings>
String filesaveLocation = null;
filesaveLocation = ConfigurationSettings.AppSettings["FileLocation"] + "\" + Format_Date + "\";
if (Directory.Exists(filesaveLocation))
The above works.
In the other program I am using
< appSettings>
< add key="FileLocation" value="D:App\Staging" />
< /appSettings>
String filesaveLocation = null;
filesaveLocation = ConfigurationSettings.AppSettings["FileLocation"] + "\" + Format_Date + "\";
if (Directory.Exists(filesaveLocation))
this works fine on my windows 7 workstattion.
However when I move the code to a production server, the code does not work.
Do I need to have the '\" in the directory path set to a different value?
Thus can you tell me what you think could be going wrong and show me code on how to solve the problem?
All replies (3)
Tuesday, January 29, 2013 3:07 PM âś…Answered
What I am saying is that D:App\Staging is a relative path and D:\App\Staging is an absolute path.
I am saying that if you consistently use Path.Combine, then the trailing \ is unnecessary.
As Wyck said in your other post, you do not need to use \ in the XML files and just adds inconsistency.
If you use Absolute paths, then you know exactly where you are going, if you use relative paths, then it will depend upon the current path that is maintained by the application.
It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.
Tuesday, January 29, 2013 1:54 PM
The \ after the drive specification is what makes it an absolute path, rather than a relative path. So for portability and conciseness, it definitely should be there. The trailing \ will only be a consideration if you are concatenating it with other path values. As I mentioned to you in another post, by using Path.Combine, the trailing \ becomes superfluous.
It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.
Tuesday, January 29, 2013 2:56 PM
So you are saying the following:
1. I should use The \ after the drive specification is what makes it an absolute path, correct? If I use the
\ after the drive name, that names it a relative path?
2. I am placing the trailing \ as part of the directory name since I will be placing some kind of file in that directory path.
So you are basically saving do not use the \ trailing as part of the name?
3. My problem is the code has been tested on lots of servers and has no problem until this point. Are you saying if I change the code to using the path as described in previous posts my problems would go away?