473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Error: Could not find a part of the path / Reading and Writing to files in ASP.Net

TC
Hello,

I'm trying to read a text file located in the top folder of the virtual
directory and I'm receiving the following error:

"Could not find a part of the path"

Below is the code that I'm using:

string MyFile;
MyFile =Request.ApplicationPath + "//sample1.txt";
StreamReader srReader;
srReader = new StreamReader(MyFile);
txtMessage.Text = srReader.ReadLine();

I have tried both "Windows" and "None" for "Authentication mode".

Any ideas?

Thanks & Regards,

TC
Nov 18 '05 #1
3 5235
Hello,

Request.ApplicationPath will return a virtual path string like
"/WebApplication1". However, StreamReader require a physical path like
"C:\inetpub\webapplication1\sample.txt". To convert a virtual path to
physical path, we can use MapPath method:

MyFile =Server.MapPath(Request.ApplicationPath + "//sample1.txt");

Hope this help,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #2
TC
Hey Luke,

Yep! It worked! DOH!

Ironically, I saw this method in some documentation and it was the 1 thing
that I didn't try :-(

Thanks Again,

TC
"[MSFT]" <lu******@online.microsoft.com> wrote in message
news:cf**************@cpmsftngxa10.phx.gbl...
Hello,

Request.ApplicationPath will return a virtual path string like
"/WebApplication1". However, StreamReader require a physical path like
"C:\inetpub\webapplication1\sample.txt". To convert a virtual path to
physical path, we can use MapPath method:

MyFile =Server.MapPath(Request.ApplicationPath + "//sample1.txt");

Hope this help,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #3

Hi, I got a similar problem just now. On my local machine I mapped th
V:\LoggerNet to a remote server folder where the real-time data com
in. I checked the file, it gets updated with the original serve
source. The code is like

streamreader sr=null;
sr = File.OpenText("V:\\LoggerNet\\newdata.dat");
text = sr.ReadToEnd();

But when I run the code, it gave error "Could not find a part of th
path "V:\LoggerNet\newdata.dat" on my webpage.

Do you have any idea why this happen?? Thanks a lot!

Jessica
[MSFT] wrote:
*Hello,

Request.ApplicationPath will return a virtual path string like
"/WebApplication1". However, StreamReader require a physical pat
like
"C:\inetpub\webapplication1\sample.txt". To convert a virtual pat
to
physical path, we can use MapPath method:

MyFile =Server.MapPath(Request.ApplicationPath + "//sample1.txt");

Hope this help,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confer
no
rights.)

-
jessic
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
1
by: Alex | last post by:
Hello, in my company, we have a diagnostic tool for hardware. Depending on the hardware projcet, a different project configuration is needed. The configuration file is written in XML and...
11
by: Wolfgang Kaml | last post by:
I am not sure if this is more of an expert question, but I am sure that they are out there. I'd like to setup a general application or bin directory on my Win2003.Net Server that will hold some...
9
by: Tim D | last post by:
Hi, I originally posted this as a reply to a rather old thread in dotnet.framework.general and didn't get any response. I thought it might be more relevant here; anyone got any ideas? My...
0
by: Joergen Bech | last post by:
Fairly new to ASP.NET 1.1. Getting the error below when running application on a web server outside of my control, but only the first time I run it: 1. After a long period of inactivity (or...
8
by: mohit | last post by:
Hi, I am creating a web application in Web Matrix on the .NET framework. I have two directories :AddUser and FormAuth in a Directory P. AddUser contains a file AddUser.aspx FormAuth contains :...
6
by: tgnelson85 | last post by:
Hello, C question here (running on Linux, though there should be no platform specific code). After reading through a few examples, and following one in a book, for linked lists i thought i would...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
0
Guido Geurs
by: Guido Geurs | last post by:
I'm writing a program that list the contents of a CDrom and also the contents of the ZIP files. When there is a bad Zip file on the CD, the program keeps traying to reed the file and after +- 50...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.