0

I'm writing a programm that runs on a Linux machine and needs to connect to a Windows SMB share.

Using Path.Join(path1, path2) it will use the forward slash / as directory separator. However the SMB share is on Windows and needs the backslash \ as separator.

Is there some easy inbuilt way to concatenate paths using a defined directory separator without just calling .Replace('/', '\\') on the result?

wertzui
  • 5,148
  • 3
  • 31
  • 51
  • Windows supports using either the backslash OR the forward slash as separators, so can't you just use `/` ? That's even [recommended by Microsoft](https://learn.microsoft.com/en-us/dotnet/api/system.io.path.directoryseparatorchar?view=net-6.0). – Matthew Watson Oct 13 '22 at 08:17
  • See https://stackoverflow.com/questions/38168391/cross-platform-file-name-handling-in-net-core – auburg Oct 13 '22 at 08:19
  • The only real solution to my problem in the linked questions is using `.Replace('/', '\\')`. I was hoping for something built into the framework so I can tell it in advance what kind of seperators I want without it using the separator of the OS my application is running on. – wertzui Oct 13 '22 at 10:55
  • 1
    @wertzui Please show the source code you use to access/use the SMB share. The `System.IO.Path` class is used for file system related path operations, not for URLs. – Progman Oct 13 '22 at 11:16
  • @Progman I'm using the https://github.com/ume05rw/EzSmb which passes the path to https://github.com/TalAloni/SMBLibrary which writes the path as UTF8-bytes in the buffer field specified by the SMB2 protocol here https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/e8fb45c1-a03d-44ca-b7ae-47385cfd7997. So, no transformation is going on, it is basically going straight into the underlying Socket and to the SMB (Windows) Server. – wertzui Oct 14 '22 at 21:17

0 Answers0