sk7730
sk7730

Reputation: 736

Read File properties

I am trying to read the file properties, For example If i change the file extension of test.txt file into test_txt.vsf, the type of file still .txt in file properties. I want to read this file extension from properties.

I am usinf below code which displays the file name extension as .vsf. But actually it's extension is .txt.

FileInfo info = new FileInfo(@"C:\Users\saravana_rajkumar\Desktop\Test_txt.vsf");
Console.WriteLine(info.Extension);

Please guide...

Upvotes: 1

Views: 324

Answers (2)

Matthew Watson
Matthew Watson

Reputation: 109547

The type of the data actually in a file is not stored anywhere by Windows. It is up to applications to determine if they can handle a file they are given.

For example, if you rename an EXE to ".txt" you can try to open it with Notepad, and it will try to open it as a text file.

When you say this:

If i change the file extension of test.txt file into test_txt.vsf, the type of file still .txt in file properties.

You are wrong. The type of the file is not still ".txt" in file properties. The file properties for file type in Windows Explorer works solely off the file suffix.

Upvotes: 3

Snake Eyes
Snake Eyes

Reputation: 16754

Do you tried to use Path.ChangeExtension method ?

Check out Path.ChangeExtension documentation in MSDN

Example:

string newFileName = Path.ChangeExtension("test_txt.txt", ".vsf");

Upvotes: 0

Related Questions