Hi Guys
I am new to C# programming and I wandered whether anyone could help me regarding this error message below:
C:\MyFirstCOMTemplate\COM\PushTemplateC\PushTemplateC.cs(86): 'PushTemplateC.PushTemplateC.PblReadFile()': not all code paths return a value
I am simply trying to get the text below:
My name is
Neil Rastogi
I am aged
25
to be output in a listbox. I have created a simple data2.txt file using streamwriter class below within a c# component:
public void PblAddFile()
{
//int PrvFile = FreeFile();
try
{
// Create a new file to work with
FileStream fsOut = File.Create("C:\\data2.txt");
StreamWriter sw = new StreamWriter (fsOut);
sw.WriteLine("My name is");
sw.WriteLine("Neil Rastogi");
sw.WriteLine("I am aged");
sw.WriteLine("25");
sw.Flush();
sw.Close();
fsOut.Close();
}
catch (Exception)
{
Console.WriteLine("Error raised writing to the file");
}
}
The method above works fine. The second method below is what is causing the error message below:
public string PblReadFile()
{
FileStream fsIn = File.OpenRead("C:\\data2.txt");
StreamReader sr = new StreamReader (fsIn);
//And read the data
while (sr.Peek() > -1)
{
lbLines.Items.Add(sr.ReadLine());
//PblReadFile() = sr.ReadLine();
return sr.ReadLine();
}
sr.Close();
fsIn.Close();
}
I am not sure really what is wrong can anyone suggest any ideas? Thanks.