Abdul Khadhar
Abdul Khadhar

Reputation: 1

How to set the File Info

I am writing this below code in my C# project. I am getting the following error:

The best overloaded method match for System.IO.File.FileInfo has some invalid arguments;

Whether the code is correct or not.

FileInfo file = new FileInfo(ViewState["value"]);

Thanks in advance

Upvotes: 0

Views: 552

Answers (2)

FIre Panda
FIre Panda

Reputation: 6637

You could do

FileInfo file = new FileInfo(ViewState["value"].ToString()); 

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1503469

My guess is that you just need to cast to string:

FileInfo file = new FileInfo((string) ViewState["value"]);

Basically ViewState[string] returns an object, and there's no FileInfo(object) constructor - that's what the compiler was complaining about.

Upvotes: 3

Related Questions