Solved

file path with streamreader

Posted on 2010-09-09
18
404 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
  • 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now