UI
<input type = "file" title="Please upload some file" name="file" />
MVC
/*below method is called from a MVC controller
this method resides for now in MVC project itself*/
public IEnumerable<CustomerTO> FetchJson(HttpPostedFile file)
{
using (StreamReader sr = new StreamReader(file.FileName))
{
{
file.saveAs("details.txt");
string json = sr.ReadToEnd();
IEnumerable<CustomerTO> customers=
JsonConvert.DeserializeObject<List<CustomerTO>>(json);
return customers;
}
}
}
When the above method in MVC project or some kind of web based project, all references are find fine.
But I am thinking to create a utility class to handle all such operations. So I created a class library project & added a class Utitlity.cs
Class Library
public IEnumerable<CustomerTO> FetchJson(HttpPostedFile file)
{
//but HttpPostedFile is throwing error.
//NOTE Ideally,I shouldn't be saving the posted file
}
Now I know FileUpload is UI control HttpPostedFile handles all operations related to this.
I can easily add reference using System.Web
but I doubt if that's right??
But how do I address my requirement then without any kind of overhead?? Memory allocation, execution & all such is very critical