Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

file path with streamreader

Posted on 2010-09-09
18
Medium Priority
?
443 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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 your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

610 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