Question

I have a string in C#

String file="\\mserver-80\docs\somedoc.doc"

Now How do I get fileInfo from the above sting. What I mean is, I want to declare something like

FileInfo fInfo = new FileInfo(file);
fileExtn = fInfo.Extension;
Was it helpful?

Solution

In C# the string should be

String file="\\\\mserver-80\\docs\\somedoc.doc";

You can also escacpe the string using the @ character, which is a better alternative:

String file=@"\\mserver-80\docs\somedoc.doc";

other than that the code should work.

OTHER TIPS

You can also try

Path.GetExtension(file)

That code will work fine, using the FileInfo class.

Simply add

using System.IO;

However, note that the \ must be escaped as \\.
Instead, you should use an @"" string, like this:

String file = @"\\mserver-80\docs\somedoc.doc"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top