1

We are designing a website using .NET

The website has a folders containing some files. User enters the name of the file and we have to fetch data from that file. On our pc in Visual Studio, we were using StreamReader like this:

StreamReader sr = new StreamReader("C:\\Users\\UserName\Documents\\Visual Studio 2012\\Projects\\teach\\uploads\\Submission\\" + filename;

But now, we are going live with our website and the problem is the file path? What should we give exactly? The files are in /compiler/Submission folder.

Akshay Gupta
  • 361
  • 1
  • 6
  • 17
  • You may want to keep your files somewhere other than your web folder - a shared network drive, or a hosted solution like AWS or Azure might be better, for lots of different reasons. – Joe Enos Apr 08 '15 at 19:23

2 Answers2

4

Use Server.MapPath

It could be something like this

var yourPath = Server.MapPath("~/uploads")

Where ~ is replaced by .NET for the root of your virtual directory.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
0

you can't access files directly using drive location.

try assume your live website at www.mydomian.com and you can view the file as

www.mydomian.com\uploads\myfile.txt

then use:

StreamReader sr = new StreamReader(@"www.mydomian.com\uploads\" + filename);

or Daniel A. White's solution

var yourPath = Server.MapPath("~/uploads/"+filename)
Community
  • 1
  • 1
A_Sk
  • 4,532
  • 3
  • 27
  • 51