How do I Get the File Path with a web app?

Posted on 2010-01-08
Last Modified: 2012-05-08

I have an .aspx page (named "confirm.aspx")written in C#.  All I want to do is append a client id and EMail variables to the end of the file "cids.txt".  

cids.txt is in the same directory as the webpage running this code (confirm.aspx).  

How do I direct the StreamWriter to open the file in appropriate directory?

My current code (which doesn't work)  tries to open c:\windows\system32\inetsrv\CIDS.TXT   Which I do not have access to (obviously).  

StreamWriter SW;

SW = File.AppendText("CIDS.TXT");

SW.WriteLine(ClientID.ToString() + ", " + EMail);


Open in new window

Question by:LindyGeek
    LVL 13

    Expert Comment

    using (var sw = new StreamWriter(MapPath("/") + "CIDS.TXT", true))
                sw.WriteLine(ClientID.ToString() + ", " + EMail);

    Open in new window

    LVL 13

    Accepted Solution

    The function: MapPath()

    take in the virtual directory and returns the physical folder location.

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now