Viewing/opening files (from Virtual Directory)

Results 1 to 2 of 2

Thread: Viewing/opening files (from Virtual Directory)

  1. #1
    Join Date
    Dec 1969

    Default Viewing/opening files (from Virtual Directory)

    I have displayed the files of a given folder using:<BR>string VirtualFolder = "/";<BR>string SubFolder = "";<BR>VirtualFolder = Server.MapPath(VirtualFolder);<BR>VirtualFolder = VirtualFolder + SubFolder;<BR>DirectoryInfo myDir = new DirectoryInfo(VirtualFolder);<BR>Response.Write (VirtualFolder);<BR>this.DataGrid1.DataSource = myDir.GetFiles();<BR>this.DataGrid1.DataBind();<BR ><BR>THIS WORKS PROPERLY. <BR>But, I would also like to view the subfolders of this directory--and, if they are clicked on, display that folder&#039;s contents.<BR>MOST IMPORTANTLY I would like to OPEN any file (i.e. Word, Excel, PDF) and display it. I have already tried:<BR><BR>Response.ContentType = "Application/pdf";<BR>string FilePath = MapPath("acrobat.pdf");<BR>Response.WriteFile(File Path);<BR>Response.End();<BR><BR>This DOES NOT WORK. It tries to open it in Notepad and keeps displaying the web page name (not the file being opened)<BR>Also used the Binary/FileStream and it says user does not have rights to open. Not sure how to bypass that. Any help is GREATLY APPRECIATED!!!<BR><BR>Thanks,<BR>Dan

  2. #2
    Join Date
    Dec 1969

    Default RE: Viewing/opening files (from Virtual Directory)

    try this:<BR><BR>Response.AppendHeader("Content-Disposition", "attachment;filename=" & strFileName)<BR>Response.ContentType = "application/octet-stream"<BR><BR>you can also change attachment to &#039;inline&#039;.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts