Click here to Skip to main content
Sign Up to vote bad
good
See more: C#4.0ASP.Net-4.0
Hi all,
 
i want to view the document on browser from code behind?
 
i am creating a temp file and then convert it to html file.
now i want to open it in browser window.how can i open it.
if i am opening it then access denies error raise.
how can i view the document on browser from code behind?
Posted 13 Aug '12 - 1:49
amit_83734


1 solution

protected void ShowFile(string URL)
       {
           if (URL != null && URL.ToString().Trim() != "")
           {
              
               FileInfo fileInfo = new FileInfo(URL);
               if (fileInfo.Exists)
               {
                   Response.Clear();
                   Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName);
                   Response.AddHeader("Content-Length", fileInfo.Length.ToString());
                   Response.ContentType = "application/octet-stream";
                   Response.Flush();
                   Response.WriteFile(fileInfo.FullName);
                   Response.End();
               }
           }
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 364
1 Arun Vasu 223
2 OriginalGriff 190
3 CPallini 163
4 Aarti Meswania 158
0 Sergey Alexandrovich Kryukov 10,169
1 OriginalGriff 7,749
2 CPallini 4,181
3 Rohan Leuva 3,482
4 Maciej Los 3,089


Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 13 Aug 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid