Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2010-01-08
2
Medium Priority
?
322 Views
Last Modified: 2012-05-08
Hi

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).  

Thanks.
StreamWriter SW;
SW = File.AppendText("CIDS.TXT");
SW.WriteLine(ClientID.ToString() + ", " + EMail);
SW.Close();

Open in new window

0
Comment
Question by:LindyGeek
  • 2
2 Comments
 
LVL 13

Expert Comment

by:zadeveloper
ID: 26214985
try:
using (var sw = new StreamWriter(MapPath("/") + "CIDS.TXT", true))
        {
            sw.WriteLine(ClientID.ToString() + ", " + EMail);
            sw.Close();
        }

Open in new window

0
 
LVL 13

Accepted Solution

by:
zadeveloper earned 500 total points
ID: 26215125
The function: MapPath()

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

580 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