Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

1 solution

C#
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();
               }
           }
}
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900