By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,334 Members | 2,776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,334 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a

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 discussion thread is closed

Replies have been disabled for this discussion.