public class SampleDataGroup
{
public string s_tmp;
public SampleDataGroup(String uniqueId, String title, String subtitle, String imagePath, String description)
{
string path = @"test.txt";
using (StreamReader sr = new StreamReader(path))
{
}
}
มันขึ้นสีแดงตลอดเลย มี error ว่า
Error 1 The best overloaded method match for 'System.IO.StreamReader.StreamReader(System.IO.Stream)' has some invalid arguments C:\Users\piyawan\documents\visual studio 2013\Projects\BookReader\BookReader\DataModel\SampleDataSource.cs 70 38 BookReader
Error 2 Argument 1: cannot convert from 'string' to 'System.IO.Stream' C:\Users\piyawan\documents\visual studio 2013\Projects\BookReader\BookReader\DataModel\SampleDataSource.cs 70 55 BookReader
System.IO.Stream src = Application.GetResourceStream(new Uri("/ProjectName;component/data/filename.txt", UriKind.Relative)).Stream;
using (StreamReader sr = new StreamReader(src))
{
string text = sr.ReadToEnd();
}
private string ReadFile(string filePath)
{
//this verse is loaded for the first time so fill it from the text file
var ResrouceStream = Application.GetResourceStream(new Uri(filePath, UriKind.Relative));
if (ResrouceStream != null)
{
Stream myFileStream = ResrouceStream.Stream;
if (myFileStream.CanRead)
{
StreamReader myStreamReader = new StreamReader(myFileStream);
//read the content here
return myStreamReader.ReadToEnd();
}
}
return "NULL";
}
String sFileReader = ReadFile("/ProjectName;component/data/filename.txt");