?
Solved

file path with streamreader

Posted on 2010-09-09
18
Medium Priority
?
448 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

840 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