Solved

file path with streamreader

Posted on 2010-09-09
18
415 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

733 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