Solved

file path with streamreader

Posted on 2010-09-09
18
420 Views
Last Modified: 2012-05-10
Hi I want to be able to have a virtual file path not a physcial how can i do this


using (var reader = new System.IO.StreamReader(@"D:\t\w.b-y.c/OSCAExtract/final.csv"))

i am using the physical one how can i change it to virtual

Please ehlp

Thanks,

R8VI
0
Comment
Question by:R8VI
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 4
  • 4
18 Comments
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33636502
use Request.MapPath("~/Yourfile.csv")
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33636540
Request.MapPath will give your path where you hosted your side, and inner path will let it know where you placed your file in yoru IIS configured web site.
0
 

Author Comment

by:R8VI
ID: 33636749
what is the namespace fpr request.mappath
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33636783
System.Web
0
 
LVL 11

Expert Comment

by:govindarajan78
ID: 33636791
use Server.Mappath

this will not work in the class files this will work only in aspx and aspx.cs

for .cs files use
HttpContext.Current.Server.MapPath
0
 

Author Comment

by:R8VI
ID: 33636816
i am using it like this changing to http:mapath ill need to change my reader

 using (var reader = new System.IO.StreamReader(@"D:\t\w.b-y.c/OSCAExtract/final.csv"))
            {
                output = reader.ReadToEnd();
            }
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33636862
where your website hosted in any of folder?

D:\t\w.b-y.c/OSCAExtract/
0
 

Author Comment

by:R8VI
ID: 33637169
website hosted in
D:\t\w.b-y.c

file i want to access in
D:\t\w.b-y.c/OE/myfile.csv

exact locations
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33637193
so you can use

request.mappath("~/OE/myfile.csv")
0
 
LVL 8

Accepted Solution

by:
Mohit Vijay earned 500 total points
ID: 33637199
using (var reader = new System.IO.StreamReader(request.mappath("~/OE/myfile.csv"))
            {
                output = reader.ReadToEnd();
            }
0
 

Author Comment

by:R8VI
ID: 33637228
so i tried

            using (var reader = new Request.MapPath("~/OE/myfile.csv"))
            {
                output = reader.ReadToEnd();
            }

but get error

'System.Web.UI.Page.Request' is a 'property' but is used like a 'type'      
0
 
LVL 11

Expert Comment

by:govindarajan78
ID: 33637252
1. if the root folder of the website is D:\t\w.b-y.c/OSCAExtract/

using (var reader = new System.IO.StreamReader(server.mappath("/final.csv"))
            {
                output = reader.ReadToEnd();
            }

2.  if the root folder of the website is D:\t\w.b-y.c/

using (var reader = new System.IO.StreamReader(server.mappath("/OSCAExtract/final.csv"))
            {
                output = reader.ReadToEnd();
            }
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33637293
error because you are using C# and I provide your it in vb.net systax sorry,.

use it like Reqeust.MapPath[""]

problem was with breaket.

you can also use SErver.MapthPath, remember to change breaket.
0
 
LVL 11

Expert Comment

by:govindarajan78
ID: 33637324
oops on my last code it should be

Server.MapPath
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33637357
Request is object of System.web.HttpRequest
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33637386
Server.MapPath returns the physical file path that corresponds to the specified virtual path whereas Request.MapPath maps the specified virtual path to a physical path.
0
 
LVL 11

Expert Comment

by:govindarajan78
ID: 33637471
@VjSoft: i think StreamReader needs a physical path

if i am not mistaken what R8VI needs is to avoid specifying directly the physical path so he can move his application to a different folder
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33637529
Yes, You are right that stream reader will work on phypath,

try to use Request.MapPath, will it not give you physical path? have you ever tried it?
0

Featured Post

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 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