Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Error: Could not find a part of the path / Reading and Writing to files in ASP.Net

Reply
Thread Tools

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

 
 
TC
Guest
Posts: n/a
 
      05-04-2004
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


 
Reply With Quote
 
 
 
 
[MSFT]
Guest
Posts: n/a
 
      05-05-2004
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.)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DirectoryNotFoundException - Could not find a part of the path "D:\". Tom Vogel ASP .Net 5 08-30-2004 03:05 AM
Error: Could not find a part of the path jessica ASP .Net 0 05-20-2004 04:16 AM
Error: Could not find a part of the path / Reading and Writing to files in ASP.Net TC ASP .Net 3 05-19-2004 12:00 AM
Error: Could not find a part of the path / Reading and Writing to files in ASP.Net TC ASP .Net Security 1 05-05-2004 02:19 AM
"Could not find a part of the path" error dsh ASP .Net 0 01-15-2004 09:58 PM



Advertisments