"The name 'Filepath' does not exist in the current context"

G

Gwen

Please assist.

New to C#. This below code is in a book it was used in VS 2005. I'm using
VS 2008.

On this line:
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(Filepath))
Error Msg:
The name 'Filepath' does not exist in the current context

Code:

using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX,
uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
public Service () {

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public string HelloWorld() {
return "Hello World";
}

private string FilePath = System.IO.Path.Combine(
Environment.GetEnvironmentVariable("Temp"),
"SavedItems.txt");
[WebMethod]
public string[] GetSavedItems()
{
using (System.IO.StreamReader reader =
new System.IO.StreamReader(FilePath))
{
string filedata = reader.ReadToEnd();
return filedata.Split('\n');
}

}
[WebMethod]

public void SaveItem(string item)
{
SaveItems(new string[] {item});
}
[WebMethod]

public void SaveItems(string[] items)
{
using (System.IO.StreamWriter writer = new
System.IO.StreamWriter(Filepath))
{
foreach (string item in items)
{
writer.WriteLine(item);
}
}
}

}

Thanks
 
J

Jeroen Mostert

Gwen said:
Please assist.

New to C#. This below code is in a book it was used in VS 2005. I'm using
VS 2008.

On this line:
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(Filepath))
Error Msg:
The name 'Filepath' does not exist in the current context
Typo. Should be "FilePath".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top