CodeDocu.com

C #: Calculate directory path from file string
 
C # Code Snippet:
Retrieve the path from a filename with the entire path and extension
 
Solution:
It checks if the position of the last backslash is shorter than the entire string length, and if it is shorter, in C #, you take the substring up to the position where the last backslash character occurs.
 

//-< correct: Folder >-
//*C:\_Daten\Desktop\Test\Test_Fotos\Karotten 2016-12-23 131034.jpg
start_Folder = "C:\\_Daten\\Karotten 2016-12-23 131034.jpg";
if (start_Folder.LastIndexOf("\\")<start_Folder.Length )
{
start_Folder= start_Folder.Substring(0, start_Folder.LastIndexOf("\\"));
}
//-</ correct: Folder >-

 
In the breakpoint under Visual Studio you can see the individual positions and lengths and the substring determination in the watch window.
C #: Calculate directory path from file string

Software Entwicklung Stuttgart NĂ¼rtingen
Suche Projekte C#, WPF, Windows App,ASP.Net, vb.Net, WinForms, SQL Server, Access, Excel