Problem with file path "\" storage and retrival differences

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I use FolderBrowserDlg for user to select a folder path then store it in the
sql table. I then retrieve it to concatenate in a sqlcommand text to retrive
files from that directory but it won't work because the database has it as
"\\Support\VMS\VMSDB" while the C# code expects to see
@"\\Support\\VMS\\VMSDB" . Is there a way to fix this?

Thanks,
alpha
 
Thank you for the reyply. I know the proper format that C# expects. My
question is: Is there a function call or somehting that can covert the path
data I retrieve from the SQL database (stored there by FolderBrowserDlg) to
the proper format.

Thanks.
 
Alpha said:
Thank you for the reyply. I know the proper format that C# expects. My
question is: Is there a function call or somehting that can covert the
path
data I retrieve from the SQL database (stored there by FolderBrowserDlg)
to
the proper format.

Thanks.

Yeah, store it in a string var and use String.Replace :)

string path = GetPathFromDb(); // Returns "\\Support\VMS\VMSDB"
path = path.Replace(@"\", @"\\");

And there ya have it :)

Mythran
 
Thank you. That'll work for me.

Mythran said:
Yeah, store it in a string var and use String.Replace :)

string path = GetPathFromDb(); // Returns "\\Support\VMS\VMSDB"
path = path.Replace(@"\", @"\\");

And there ya have it :)

Mythran
 
Can you tell me what's that "@" for ? I see that in several string function
but not sure what it's for. Thanks.
 
String literal. It allows you to use back slashes or whatever you want
without escaping it.
 
Well, not quite. It still doesn't work. I debug the steps and the string
var strATSPath = @"\\\\support\\VMS\\VMSDB" but the Directory.Getfiles
responded with directory not found. Does it just not like the Server name
instead of C drive? or is it the 4 back slashes"\\\\"?

Thanks.


try
{
scGetPath = new SqlCommand("select LogFilePath from Admin", conDB);
strATSPath = scGetPath.ExecuteScalar().ToString();
strATSPath = strATSPath.Replace(@"\", @"\\");
}
catch(Exception ex)
{
MessageBox.Show("Error getting the ATS file path : " + ex.ToString()+
"Please contact your support person.", "VMS - ATS file path error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}

//Get the latest ATS Access DB file name
try
{//@"C:\\VMS\\VMSDB"
string[] ATSFiles = Directory.GetFiles(strATSPath, "Ats*Db.mdb");
Array.Sort(ATSFiles);
NewATS= ATSFiles[ATSFiles.Length - 1];
}
 
Alpha said:
Well, not quite. It still doesn't work. I debug the steps and the string
var strATSPath = @"\\\\support\\VMS\\VMSDB" but the Directory.Getfiles
responded with directory not found. Does it just not like the Server name
instead of C drive? or is it the 4 back slashes"\\\\"?

Thanks.

Well, since you are using the @ symbol, don't escape the string..IE:

string strATSPath = @"\\support\VMS\VMSDB";

HTH :)

Mythran
 
Ok, I finally figured out the problem. I forgot to share the folder. Dah...
Thanks for your help.

FYI, it still needs the double slashes format for the directory.getfiles.
However, before I concatenate into the SQL query string I string.replace it
back to the single slash for it to work.

Thanks, Alpha
 
Back
Top