CS.NET -Performing File Operations



Using Path class to perform File Operations

 using system.IO; //File Operations 
 public void getFileProps()
        {
         
        string  strFileName  = "C:\\Hima\\syntaxhelp.txt";
         // Output  SyntaxHelp.txt
        Response.Write("File Name is" +Path.GetFileName(strFileName));

        // Output .txt
        Response.Write("File Extension is"+Path.GetExtension(strFileName));

        // Output syntaxhelp
        Response.Write("File with out Extension is"+Path.GetFileNameWithoutExtension(strFileName));

        // Output C:\Hima\syntaxhelp.txt
        Response.Write("File Full Path is  "+Path.GetFullPath(strFileName));
        // Output  C:
        Response.Write("File Root Path is "+Path.GetPathRoot(strFileName));

        // Output C:\Hima
        Response.Write("Directory Name is"+Path.GetDirectoryName(strFileName));
        }

Share |

 Cant find the page you are looking for?
 Help us to improve by adding the content that you are looking for.
 Leave a feedback
 We look forward to hear your comments and feedback.