Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gwen - 01 Mar 2008 21:40 GMT
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
Jeroen Mostert - 01 Mar 2008 22:04 GMT
> Please assist.
>
[quoted text clipped - 5 lines]
> Error Msg:
> The name 'Filepath' does not exist in the current context

Typo. Should be "FilePath".

--
J.
Gwen - 01 Mar 2008 23:10 GMT
Thank you!

> > Please assist.
> >
[quoted text clipped - 10 lines]
> --
> J.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.