0

I want to open a file which is saved in my local directory folder in asp.net c#. I have tried filestream like this:

path = TreeView1.SelectedNode.Value.ToString(); // file path (D:\projects\Content\Media\xxxx.PDF )

if (IsPostBack)
{
    path = TreeView1.SelectedNode.Value.ToString();

    FileInfo fileInfo = new FileInfo(path);
    if (fileInfo.Exists)
    {
        FileStream fileStream = fileInfo.Open(FileMode.Open, FileAccess.Read);
        StreamReader reader = new StreamReader(fileStream);
    }
}
Mike de Klerk
  • 11,906
  • 8
  • 54
  • 76
user3288804
  • 423
  • 1
  • 5
  • 11
  • 1
    What is your query? It's a bit confusion to understand. – Saswat Aug 12 '15 at 12:50
  • similar post [http://stackoverflow.com/questions/20354978/opening-a-text-file-on-the-local-system-from-an-asp-net-web-application][1] hope this helps you [1]: http://stackoverflow.com/questions/20354978/opening-a-text-file-on-the-local-system-from-an-asp-net-web-application – bhavikshah28 Aug 12 '15 at 12:51
  • What is the problem? What happens when you try to open the file? What do you expect to happen? – cbp Aug 12 '15 at 12:59
  • The file is saved at my local drive folder,and bound with treeview node. once i click that file name(node), wants to open that file. – user3288804 Aug 13 '15 at 04:38
  • @bhavikshah28 Thanks.Got hint by mentioned link. – user3288804 Aug 17 '15 at 10:13

1 Answers1

0

As per my understanding of your question you are trying open the file means you are trying to launch the file If i am right use this

System.Diagnostics.Process.Start(@"Your_PDF_File_Path");

Edit:Here is an easy option for displaying pdf file in html5.

<embed src="Your_File.pdf" width="800px" height="2100px">
shreesha
  • 1,811
  • 2
  • 21
  • 30
  • Yes, without using dignostic.process.start want to open file in browser. the file is saved in my local drive,and bound with treeview node. once i click that file name, wants to open file. – user3288804 Aug 13 '15 at 04:36
  • If you want to display pdf file in browser i would suggest looking at [PDF.js](http://mozilla.github.io/pdf.js/) or [PDFObject](http://pdfobject.com/) – shreesha Aug 13 '15 at 06:47